Guidelines
When it comes to linked list practice makes perfect, but there are few tricks you should remember when dealing with them:
// Reverse linked list
while(next != null){
curr = next;
next = next.next;
curr.next = prev;
prev = curr;
}
// use dummy pointer to make the implemenation easier
ListNode dummy = new ListNode(-1, null)
ListNode iter = dummy;
// fast, slow pointer
ListNode slow = head, fast = head;
while(fast != null && fast.next != null){
slow = slow.next;
fast = fast.next.next;
}
return slow;
// skipping an element by checking and relinking ahead
if(curr.next.val == val){
curr.next = curr.next.next;
}
while (l1 != null || l2 != null || carry != 0) // for adding two lists
// reversing a sublist in place bubble out the first element to end
for(int i = 0; i < right - left; ++i){
ListNode next = iter.next;
iter.next = next.next;
next.next = start.next;
start.next = next;
}