标签:new int public wap amp null swap color turn
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { public ListNode swapPairs(ListNode head) { if(head==null) return null; ListNode dummy = new ListNode(0); dummy.next = head; ListNode p= dummy; while(p.next!=null&&p.next.next!=null) { ListNode temp = p.next; p.next = p.next.next; temp.next = p.next.next; p.next.next = temp; p = temp; } return dummy.next; } }
3ms-4ms 比 递归快1ms。2ms答案类似。可以了。
Leetcode24. Swap Nodes in Pairs
标签:new int public wap amp null swap color turn
原文地址:https://www.cnblogs.com/chason95/p/10133692.html