Skip to content

Commit a6d521a

Browse files
swap nodes in pairs
1 parent a282d79 commit a6d521a

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

‎EASY/src/easy/SwapNodesinPairs.java

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package easy;
2+
3+
import classes.ListNode;
4+
5+
public class SwapNodesinPairs {
6+
7+
public ListNode swapPairs(ListNode head) {
8+
if(head == null || head.next == null) return head;
9+
ListNode second = head.next;
10+
ListNode third = second.next;
11+
second.next = head;
12+
head.next = swapPairs(third);
13+
return second;
14+
}
15+
16+
}

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
|58|[Length of Last Word](https://leetcode.com/problems/length-of-last-word/)|[Solution](../../blob/master/EASY/src/easy/LengthofLastWord.java)|O(n)|O(1)|Easy|
5353
|56|[Merge Intervals](https://leetcode.com/problems/merge-intervals/)|[Solution](../../blob/master/HARD/src/hard/MergeIntervals.java)|O(n*logn)|O(1)|Hard|
5454
|43|[Multiply Strings](https://leetcode.com/problems/multiply-strings/)|[Solution]|||Medium
55+
|24|[Swap Nodes in Pairs](https://leetcode.com/problems/swap-nodes-in-pairs/)|[Solution](../../blob/master/EASY/src/easy/SwapNodesinPairs.java)|O(n)|O(1)|Easy| Recursion, LinkedList
5556
|23|[Merge k Sorted Lists](https://leetcode.com/problems/merge-k-sorted-lists/)|[Solution](../../blob/master/HARD/src/hard/MergeKSortedList.java)|O(n*logk)|O(logk)|Hard|Heap
5657
|21|[Merge Two Sorted Lists](https://leetcode.com/problems/merge-two-sorted-lists/)|[Solution](../../blob/master/EASY/src/easy/MergeTwoSortedLists.java)|O(n)|O(1)|Easy|
5758
|17|[Letter Combinations of a Phone Number](https://leetcode.com/problems/letter-combinations-of-a-phone-number/)|[Solution](../../blob/master/MEDIUM/src/medium/LetterCombinationsofaPhoneNumber.java)|O(n*4^n)|O(n)|Medium|Backtracking

0 commit comments

Comments
 (0)