Methods
(static) merge(list1, list2) → {LinkedList}
You are given the heads of two sorted linked lists list1 and list2.Merge the two lists in a one sorted list.
The list should be made by splicing together the nodes of the first two lists.
Return the head of the merged linked list.
For example,
Input: list1 = 1 -> 2 -> 4 , list2 = 1 -> 3 -> 4
Output: 1 -> 1 -> 2 -> 3 -> 4 -> 4
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
list1 |
LinkedList
|
|
list2 |
LinkedList
|
Returns:
- Type:
-
LinkedList
New list which has both the list merged in ascending order.
recursiveReverse(head) → {ListNode}
Given the head of a singly linked list, reverse the list, and return the reversed list.
For example,
Input: 1 -> 2 -> 3 -> 4 -> 5
Output: 5 -> 4 -> 3 -> 2 -> 1
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
head |
ListNode
|
Head of linked list |
Returns:
- Type:
-
ListNode
Reversed linked list
reverse(head) → {ListNode}
Given the head of a singly linked list, reverse the list, and return the reversed list.
binary
For example,
Input: 1 -> 2 -> 3 -> 4 -> 5
Output: 5 -> 4 -> 3 -> 2 -> 1
- Source:
- See:
Parameters:
Name | Type | Description |
---|---|---|
head |
ListNode
|
Head of linked list |
Returns:
- Type:
-
ListNode
Reversed linked list