Leetcode_024_Swap_Nodes_In_Pairs.java - package...

  • No School
  • AA 1
  • 1

This preview shows page 1 out of 1 page.

package coding.leetcode; /** * Created by Administrator on 2017-07-22. */ public class Leetcode_024_Swap_Nodes_In_Pairs { public class ListNode { int val; ListNode next; ListNode(int x) { val = x; } } public ListNode swapPairs(ListNode head) { ListNode sentinel = new ListNode(0); sentinel.next = head; ListNode prev = sentinel; ListNode current = head; while(current != null){ ListNode next = current.next; if(next == null) break; prev.next = next; current.next = next.next; next.next = current; prev = current; current = current.next;
Image of page 1

You've reached the end of your free preview.

Want to read the whole page?

  • Fall '19
  • Val, Void type, South African National Roads Agency, public class ListNode, public class Leetcode

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

Stuck? We have tutors online 24/7 who can help you get unstuck.
A+ icon
Ask Expert Tutors You can ask You can ask You can ask (will expire )
Answers in as fast as 15 minutes