Skip to content

Commit 67037dc

Browse files
refactor 24
1 parent 13b7642 commit 67037dc

File tree

1 file changed

+10
-9
lines changed
  • src/main/java/com/fishercoder/solutions

1 file changed

+10
-9
lines changed

src/main/java/com/fishercoder/solutions/_24.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,17 @@
1414
1515
*/
1616
public class _24 {
17-
18-
public ListNode swapPairs(ListNode head) {
19-
if (head == null || head.next == null) {
20-
return head;
17+
public static class Solution1 {
18+
public ListNode swapPairs(ListNode head) {
19+
if (head == null || head.next == null) {
20+
return head;
21+
}
22+
ListNode second = head.next;
23+
ListNode third = second.next;
24+
second.next = head;
25+
head.next = swapPairs(third);
26+
return second;
2127
}
22-
ListNode second = head.next;
23-
ListNode third = second.next;
24-
second.next = head;
25-
head.next = swapPairs(third);
26-
return second;
2728
}
2829

2930
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy