Swap Nodes in Pairs
来源:互联网 发布:网红淘宝店前十名 编辑:程序博客网 时间:2024/06/05 00:55
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class Solution { public ListNode swapPairs(ListNode head) { ListNode fakeHead = new ListNode(-1); fakeHead.next = head; head = fakeHead; while(head.next != null && head.next.next != null){ swap(head); head = head.next.next; } return fakeHead.next; } public void swap(ListNode node){ ListNode n1 = node.next; ListNode n2 = node.next.next; node.next = n2; n1.next = n2.next; n2.next = n1; }}
0 0
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes In Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- Swap Nodes in Pairs
- 关于运行JAR包中的class
- 如何通过SEO让客户买单
- 关键词选择误区
- 排序算法(三)-- 堆排序
- LeetCode刷题笔录Subsets II
- Swap Nodes in Pairs
- Topcoder SRM 635 Div2 1000 (一种 O(n) 求一棵树中最长连续边 长度的方法)
- 谐振器和振荡器的差异分析
- 使用Batik绘制SVG图并保存为png图像格式
- 15条技巧提高你的写作技巧
- 如何阅读的一点笔记整理
- 【iOS】Swift中扩展extension与协议protocol
- [Leetcode] Generate Parenthesis
- 用 MQL5 创建外汇交易界面