首页 > 其他 > 详细

LeetCode 24. 两两交换链表中的节点

时间:2019-09-23 20:04:57      阅读:101      评论:0      收藏:0      [点我收藏+]
执行用时 :0 ms, 在所有 Java 提交中击败了100.00% 的用户
内存消耗 :34.2 MB, 在所有 Java 提交中击败了86.60%的用户
 
 1 public ListNode swapPairs(ListNode head) {
 2         if (head == null || head.next == null) return head;
 3         ListNode a = head, b = head.next, c, last = null;
 4         head = b;
 5         while (a != null && b != null) {
 6             c = b.next;
 7             b.next = a;
 8             a.next = c;
 9             if (last != null) last.next = b;
10             last = a;
11 
12             a =c;
13             if (a != null) b = a.next;
14         }
15         return head;
16     }

 

LeetCode 24. 两两交换链表中的节点

原文:https://www.cnblogs.com/towerbird/p/11574036.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!