Skip to content
Advertisement

Tag: singly-linked-list

Removing Duplicates from linked list. Why are the position of “prev = head” and “p2 = p2.next” not outside the else statement?

For the first function, shouldn’t “prev = head” be outside of else because we want to set the previous every time before we change the head value? For the second function, shouldn’t “p2 = p2.next” be outside of else because we want to go next every time? Thank you guys. Answer Shouldn’t “p2 = p2.next” be outside of else because

Leetcode #2, getting detected a cycle error

I was trying to solve leetcode#2, You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return it as a linked list. You may assume the two numbers do not contain any leading zero, except the number 0

Advertisement