We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 24a4852 commit 4349aa5Copy full SHA for 4349aa5
1.SwapAdjacentNodesOfLinkedList.java
@@ -0,0 +1,32 @@
1
+/**
2
+ * Definition for singly-linked list.
3
+ * public class ListNode {
4
+ * int val;
5
+ * ListNode next;
6
+ * ListNode() {}
7
+ * ListNode(int val) { this.val = val; }
8
+ * ListNode(int val, ListNode next) { this.val = val; this.next = next; }
9
+ * }
10
+ */
11
+class Solution {
12
+
13
14
+ public ListNode swapPairs(ListNode node) {
15
16
+ if (node == null || node.next == null) {
17
+ return node;
18
+ }
19
20
21
+ ListNode remaining = node.next.next;
22
+ ListNode newhead = node.next;
23
+ node.next.next = node;
24
+ node.next = swapPairs(remaining);
25
+ return newhead;
26
27
28
29
30
31
32
+}
0 commit comments