Solution 1: accepted
|
|
Why?
Given [1,2,3,4,5,6]1slow.next = slow.next.next;
will change both dummy and slow (but not head) whereas123slow = slow.next;//orslow = slow.next.next;
will only change slow, not dummy
Why?
If we retain both12dummy.next = head;slow.next = head;
[1] 1 will return [1] instead of [], so we need to discard one of them