Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Definition for singly-linked list.
- * public class ListNode {
- * int val;
- * ListNode next;
- * ListNode(int x) { val = x; }
- * }
- */
- class Solution {
- public ListNode swapPairs(ListNode head) {
- ListNode temp = new ListNode(0);
- temp.next = head;
- ListNode curr = temp;
- while(curr.next != null && curr.next.next != null){
- ListNode first = curr.next;
- ListNode second = curr.next.next;
- first.next = second.next;
- second.next = first;
- curr.next = second;
- curr.next.next = first;
- curr = first;
- }
- return temp.next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement