LeetCode - Swap Nodes in Pairs - Frequent
来源:互联网 发布:浙江省数据库三级 编辑:程序博客网 时间:2024/06/05 20:10
https://leetcode.com/problems/swap-nodes-in-pairs/
这种题都可以用dummy node来解决,不过要注意其中node指针换来换去的细节问题,很容易错。
代码如下:
public class Solution { public ListNode swapPairs(ListNode head) { if(head==null || head.next == null) return head; ListNode dummy = new ListNode(0); ListNode traverse = dummy; while(head!=null && head.next!=null){ ListNode tmp = head.next.next; traverse.next = head.next; head.next.next = head; traverse = head; head = tmp; } traverse.next = head; return dummy.next; }}
0 0
- LeetCode - Swap Nodes in Pairs - Frequent
- LeetCode:Swap Nodes in Pairs
- LeetCode: Swap Nodes in Pairs
- [Leetcode] Swap Nodes in Pairs
- LeetCode : Swap Nodes in Pairs
- [LeetCode] Swap Nodes in Pairs
- Leetcode: Swap nodes in pairs
- [LeetCode]Swap Nodes in Pairs
- [LeetCode]Swap Nodes in Pairs
- LeetCode-Swap Nodes in Pairs
- LeetCode - Swap Nodes in Pairs
- LeetCode | Swap Nodes in Pairs
- 【leetcode】Swap Nodes in Pairs
- Leetcode: Swap Nodes in Pairs
- LeetCode - Swap Nodes in Pairs
- 【LeetCode】Swap Nodes in Pairs
- Leetcode: Swap Nodes in Pairs
- Leetcode Swap Nodes in Pairs
- “计算机图形学”实践教学资源库的设计与建设
- 钻石恒久远,一颗永相传
- 从线框模型到表面模型绘制技术的联想
- 我的图形学网站,备忘
- 扩大矩形函数和缩小矩形函数的用法
- LeetCode - Swap Nodes in Pairs - Frequent
- CRect::operator LPRECT
- Win7操作系统下安装VC++6.0、MSDN并使用MFC绘图
- 孔令德的计算机图形学课程实验
- Android中的Shape使用总结
- java后端系统架构之jvm远程监控
- iOS开发之多线程编程 (2)
- [COGS902]乐曲主题
- Struts2漏洞分析