public static ListNode swapPairs(ListNode head) {

    if (head == null) {
      return null;
    }

    ListNode result = head;
    if (head.next != null) {
      result = head.next;
    }

    while (head != null && head.next != null) {
      ListNode third = head.next.next;
      ListNode forth = null;
      if (third != null) {
        forth = third.next;
      }
      head.next.next = head;
      if (forth != null) {
        head.next = forth;
      } else {
        head.next = third;
      }
      head = third;
    }

    return result;
  }