Problem 24: Swap Nodes in Pairs
思路
考察的主要就是两根指针的移动,和上一题很像
易错点
dummy node 必须要存在,因为涉及到交换 node 的时候,“头”就乱了。
while 的循环条件,是 head.next.next != null; 因为要涉及两根指针 n1 和 n2
交换完指针记得 update head 指针
Last updated
考察的主要就是两根指针的移动,和上一题很像
dummy node 必须要存在,因为涉及到交换 node 的时候,“头”就乱了。
while 的循环条件,是 head.next.next != null; 因为要涉及两根指针 n1 和 n2
交换完指针记得 update head 指针
Last updated