[leetcode]24. Swap Nodes in Pairs -- JavaScript 代码
2016-08-18 15:04
525 查看
/** * Definition for singly-linked list. * function ListNode(val) { * this.val = val; * this.next = null; * } */ /** * @param {ListNode} head * @return {ListNode} */ var swapPairs = function(head) { if(head===null || head.next===null) return head; var tmp = head; head = head.next; var thelast = null; while(tmp!==null && tmp.next!==null){ next = tmp.next; next2 = next.next; next.next = tmp; tmp.next = next2; if(thelast!==null){ thelast.next = next; } thelast = tmp; tmp = next2; } return head; };
相关文章推荐
- Leetcode ☞ 24. Swap Nodes in Pairs ☆
- 24. Swap Nodes in Pairs Leetcode Python
- [leetcode] 【链表】24. Swap Nodes in Pairs
- leetcode 24. Swap Nodes in Pairs
- leetcode 24. Swap Nodes in Pairs(链表)
- LeetCode *** 24. Swap Nodes in Pairs
- <LeetCode OJ> 24. Swap Nodes in Pairs
- leetcode 24. Swap Nodes in Pairs
- 24.[Leetcode]Swap Nodes in Pairs
- LeetCode 24. Swap Nodes in Pairs 解题报告
- leetCode 24. Swap Nodes in Pairs (双数交换节点) 解题思路和方法
- LeetCode 24. Swap Nodes in Pairs
- 【LeetCode】24. Swap Nodes in Pairs (3 solutions)
- [leetcode] 24. Swap Nodes in Pairs 解题报告
- leetcode 24. Swap Nodes in Pairs
- LeetCode 24. Swap Nodes in Pairs
- 24. Swap Nodes in Pairs | Java最短代码实现
- 【leetcode】24. Swap Nodes in Pairs
- leetcode 24. Swap Nodes in Pairs
- (Java)LeetCode-24. Swap Nodes in Pairs