Leetcode 24. Swap Nodes in Pairs
来源:互联网 发布:数据校验方式 编辑:程序博客网 时间:2024/05/26 12:53
leetcode 24. Swap Nodes in Pairs
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public class Solution { public ListNode swapPairs(ListNode head) { ListNode p = new ListNode(-1); p.next = head; ListNode ans = p; ListNode s = head; if(s==null) return head; // ==0 if(s.next==null) return head;//==1 ListNode f = head.next; while(f!=null){ // two pointer if((f.next!=null&&f.next.next==null ||f.next==null)) { p.next = f; s.next = f.next; f.next = s; break; } ListNode sNew = f.next; ListNode fNew = sNew.next; p.next = f; f.next = s; s.next = sNew; p = s; s = sNew; f = fNew; } return ans.next; }}
0 0
- [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] 24.Swap Nodes in Pairs
- **LeetCode 24. Swap Nodes in Pairs
- 24. Swap Nodes in Pairs LeetCode
- 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】24. 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
- 如何在移动设备上运行 TensorFlow
- 【leetcode】92. Reverse Linked List II
- HashMap的工作原理
- 九度oj题目1163:素数
- override的方法,为什么会被自动执行?
- Leetcode 24. Swap Nodes in Pairs
- 单源最短路径-Dijkstra算法
- 字符串倒序显示
- Java实现匹配一个给定输入的字符串中汉字、数字、英文字母、空格数量
- mac jdk安装目录
- [2017-AspNet-MVC4] 简单加法的演化-2-小数加法
- linux使用---15.源码编译insight及使用
- 玲珑杯-萌萌哒的第六题
- 排序--快速排序学习