985. Insert node before tail in Doubly Linked List
Given the head of a doubly linked list and an integer X, insert a node with value X before the tail of the linked list and return the head of the modified list.
Example 1:
Input: head = [1, 2, 4], X = 3
Output: head = [1, 2, 3, 4]
Explanation: 3 was added before the last node.
Example 2:
Input: head = [4], X = 6
Output: head = [6, 4]
Explanation: 6 was added before 4, note that the head was changed as a result.
Now Your Turn!
Pick the correct output for the given inputInput: head = [4, 5], X = 6
Still unsure what the problem is asking ?
Let’s go through a few more examples, step by step, to make it clearer.
Constraints:
- n == Number of nodes in the Linked List
- 1 <= n <= 100
- 0 <= ListNode.val <= 100
- 0 <= X <= 100