MCPcopy Index your code
hub / github.com/Blankj/awesome-java-leetcode / swapPairs

Method swapPairs

src/com/blankj/medium/_0024/Solution.java:22–33  ·  view source on GitHub ↗
(ListNode head)

Source from the content-addressed store, hash-verified

20// }
21
22 public ListNode swapPairs(ListNode head) {
23 ListNode preHead = new ListNode(0), cur = preHead;
24 preHead.next = head;
25 while (cur.next != null && cur.next.next != null) {
26 ListNode temp = cur.next.next;
27 cur.next.next = temp.next;
28 temp.next = cur.next;
29 cur.next = temp;
30 cur = cur.next.next;
31 }
32 return preHead.next;
33 }
34
35 public static void main(String[] args) {
36 Solution solution = new Solution();

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected