My simple java sulotion

  • 0

    I add an extra Node in front of the head ,so I can deal the Nodes every three in the same way.Here is the code

    public ListNode swapPairs(ListNode head) {
            if( ==null)
            	return head;
            ListNode pre = new ListNode(-1);
   = head;
            ListNode current = pre;
            while(!=null &&!=null){
            	ListNode temp =;
    = temp;
            	current =;

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.