Given a linked list, swap every two adjacent nodes and return its head.
For example,
Given 1->2->3->4, you should return the list as 2->1->4->3.
Your algorithm should use only constant space. You may not modify the values in the list, only nodes itself can be changed.

本文介绍了一种链表相邻节点交换算法,通过使用虚拟头结点和迭代方式,实现链表中每两个相邻节点的交换。算法仅使用常量空间,不修改节点值,仅改变节点指向。
317

被折叠的 条评论
为什么被折叠?



