Skip to content

Commit 7750bed

Browse files
authored
Added tasks 80-92
1 parent eb5fdc7 commit 7750bed

File tree

16 files changed

+430
-0
lines changed

16 files changed

+430
-0
lines changed

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
883883
| 0283 |[Move Zeroes](src/main/ts/g0201_0300/s0283_move_zeroes/solution.ts)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 1 | 82.86
884884
| 0001 |[Two Sum](src/main/ts/g0001_0100/s0001_two_sum/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 1 | 89.70
885885
| 0058 |[Length of Last Word](src/main/ts/g0001_0100/s0058_length_of_last_word/solution.ts)| Easy | String | 0 | 100.00
886+
| 0080 |[Remove Duplicates from Sorted Array II](src/main/ts/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/solution.ts)| Medium | Array, Two_Pointers | 40 | 99.63
886887
| 0189 |[Rotate Array](src/main/ts/g0101_0200/s0189_rotate_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 1 | 86.17
887888
| 0055 |[Jump Game](src/main/ts/g0001_0100/s0055_jump_game/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
888889
| 0075 |[Sort Colors](src/main/ts/g0001_0100/s0075_sort_colors/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
@@ -1005,8 +1006,10 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
10051006

10061007
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10071008
|-|-|-|-|-|-
1009+
| 0088 |[Merge Sorted Array](src/main/ts/g0001_0100/s0088_merge_sorted_array/solution.ts)| Medium | Two_Pointers, Linked_List | 0 | 100.00
10081010
| 0027 |[Remove Element](src/main/ts/g0001_0100/s0027_remove_element/solution.ts)| Easy | Array, Two_Pointers | 0 | 100.00
10091011
| 0026 |[Remove Duplicates from Sorted Array](src/main/ts/g0001_0100/s0026_remove_duplicates_from_sorted_array/solution.ts)| Easy | Top_Interview_Questions, Array, Two_Pointers | 0 | 100.00
1012+
| 0080 |[Remove Duplicates from Sorted Array II](src/main/ts/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/solution.ts)| Medium | Array, Two_Pointers | 40 | 99.63
10101013
| 0169 |[Majority Element](src/main/ts/g0101_0200/s0169_majority_element/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Sorting, Counting, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
10111014
| 0189 |[Rotate Array](src/main/ts/g0101_0200/s0189_rotate_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 1 | 86.17
10121015
| 0121 |[Best Time to Buy and Sell Stock](src/main/ts/g0101_0200/s0121_best_time_to_buy_and_sell_stock/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Big_O_Time_O(N)_Space_O(1) | 1 | 96.44
@@ -1077,9 +1080,12 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
10771080
| 0002 |[Add Two Numbers](src/main/ts/g0001_0100/s0002_add_two_numbers/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Big_O_Time_O(max(N,M))_Space_O(max(N,M)), AI_can_be_used_to_solve_the_task | 2 | 95.82
10781081
| 0021 |[Merge Two Sorted Lists](src/main/ts/g0001_0100/s0021_merge_two_sorted_lists/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 1 | 51.21
10791082
| 0138 |[Copy List with Random Pointer](src/main/ts/g0101_0200/s0138_copy_list_with_random_pointer/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Linked_List, Big_O_Time_O(N)_Space_O(N) | 49 | 72.42
1083+
| 0092 |[Reverse Linked List II](src/main/ts/g0001_0100/s0092_reverse_linked_list_ii/solution.ts)| Medium | Linked_List | 0 | 100.00
10801084
| 0025 |[Reverse Nodes in k-Group](src/main/ts/g0001_0100/s0025_reverse_nodes_in_k_group/solution.ts)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 0 | 100.00
10811085
| 0019 |[Remove Nth Node From End of List](src/main/ts/g0001_0100/s0019_remove_nth_node_from_end_of_list/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 0 | 100.00
1086+
| 0082 |[Remove Duplicates from Sorted List II](src/main/ts/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/solution.ts)| Medium | Two_Pointers, Linked_List | 0 | 100.00
10821087
| 0061 |[Rotate List](src/main/ts/g0001_0100/s0061_rotate_list/solution.ts)| Medium | Two_Pointers, Linked_List | 0 | 100.00
1088+
| 0086 |[Partition List](src/main/ts/g0001_0100/s0086_partition_list/solution.ts)| Medium | Two_Pointers, Linked_List | 0 | 100.00
10831089
| 0146 |[LRU Cache](src/main/ts/g0101_0200/s0146_lru_cache/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Design, Linked_List, Doubly_Linked_List, Big_O_Time_O(1)_Space_O(capacity) | 97 | 81.52
10841090

10851091
#### Top Interview 150 Binary Tree General
@@ -1217,6 +1223,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
12171223
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
12181224
|-|-|-|-|-|-
12191225
| 0001 |[Two Sum](src/main/ts/g0001_0100/s0001_two_sum/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n), AI_can_be_used_to_solve_the_task | 1 | 89.70
1226+
| 0088 |[Merge Sorted Array](src/main/ts/g0001_0100/s0088_merge_sorted_array/solution.ts)| Medium | Two_Pointers, Linked_List | 0 | 100.00
12201227

12211228
#### Day 3 Array
12221229

@@ -1362,6 +1369,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
13621369
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
13631370
|-|-|-|-|-|-
13641371
| 0160 |[Intersection of Two Linked Lists](src/main/ts/g0101_0200/s0160_intersection_of_two_linked_lists/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Hash_Table, Two_Pointers, Linked_List, Big_O_Time_O(M+N)_Space_O(1) | 65 | 72.36
1372+
| 0082 |[Remove Duplicates from Sorted List II](src/main/ts/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/solution.ts)| Medium | Two_Pointers, Linked_List | 0 | 100.00
13651373

13661374
#### Day 12 Linked List
13671375

@@ -1525,6 +1533,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
15251533

15261534
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
15271535
|-|-|-|-|-|-
1536+
| 0082 |[Remove Duplicates from Sorted List II](src/main/ts/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/solution.ts)| Medium | Two_Pointers, Linked_List | 0 | 100.00
15281537
| 0015 |[3Sum](src/main/ts/g0001_0100/s0015_3sum/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 30 | 91.56
15291538

15301539
#### Day 4 Two Pointers
@@ -1695,7 +1704,12 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
16951704
| 0098 |[Validate Binary Search Tree](src/main/ts/g0001_0100/s0098_validate_binary_search_tree/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Data_Structure_I_Day_14_Tree, Level_1_Day_8_Binary_Search_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
16961705
| 0096 |[Unique Binary Search Trees](src/main/ts/g0001_0100/s0096_unique_binary_search_trees/solution.ts)| Medium | Dynamic_Programming, Math, Tree, Binary_Tree, Binary_Search_Tree, Dynamic_Programming_I_Day_11, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
16971706
| 0094 |[Binary Tree Inorder Traversal](src/main/ts/g0001_0100/s0094_binary_tree_inorder_traversal/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Data_Structure_I_Day_10_Tree, Udemy_Tree_Stack_Queue, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
1707+
| 0092 |[Reverse Linked List II](src/main/ts/g0001_0100/s0092_reverse_linked_list_ii/solution.ts)| Medium | Linked_List, Top_Interview_150_Linked_List | 0 | 100.00
1708+
| 0088 |[Merge Sorted Array](src/main/ts/g0001_0100/s0088_merge_sorted_array/solution.ts)| Medium | Two_Pointers, Linked_List, Top_Interview_150_Linked_List | 0 | 100.00
1709+
| 0086 |[Partition List](src/main/ts/g0001_0100/s0086_partition_list/solution.ts)| Medium | Two_Pointers, Linked_List, Top_Interview_150_Linked_List | 0 | 100.00
16981710
| 0084 |[Largest Rectangle in Histogram](src/main/ts/g0001_0100/s0084_largest_rectangle_in_histogram/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Stack, Monotonic_Stack, Big_O_Time_O(n_log_n)_Space_O(log_n) | 15 | 72.81
1711+
| 0082 |[Remove Duplicates from Sorted List II](src/main/ts/g0001_0100/s0082_remove_duplicates_from_sorted_list_ii/solution.ts)| Medium | Two_Pointers, Linked_List, Data_Structure_II_Day_11_Linked_List, Algorithm_II_Day_3_Two_Pointers, Top_Interview_150_Linked_List | 0 | 100.00
1712+
| 0080 |[Remove Duplicates from Sorted Array II](src/main/ts/g0001_0100/s0080_remove_duplicates_from_sorted_array_ii/solution.ts)| Medium | Array, Two_Pointers, Udemy_Arrays, Top_Interview_150_Array/String | 40 | 99.63
16991713
| 0079 |[Word Search](src/main/ts/g0001_0100/s0079_word_search/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Backtracking, Algorithm_II_Day_11_Recursion_Backtracking, Top_Interview_150_Backtracking, Big_O_Time_O(4^(m\*n))_Space_O(m\*n) | 243 | 85.30
17001714
| 0078 |[Subsets](src/main/ts/g0001_0100/s0078_subsets/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Backtracking, Algorithm_II_Day_9_Recursion_Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(2^n)_Space_O(n\*2^n) | 0 | 100.00
17011715
| 0077 |[Combinations](src/main/ts/g0001_0100/s0077_combinations/solution.ts)| Medium | Backtracking, Algorithm_I_Day_11_Recursion_Backtracking, Top_Interview_150_Backtracking | 46 | 96.14
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
80\. Remove Duplicates from Sorted Array II
2+
3+
Medium
4+
5+
Given an integer array `nums` sorted in **non-decreasing order**, remove some duplicates [**in-place**](https://en.wikipedia.org/wiki/In-place_algorithm) such that each unique element appears **at most twice**. The **relative order** of the elements should be kept the **same**.
6+
7+
Since it is impossible to change the length of the array in some languages, you must instead have the result be placed in the **first part** of the array `nums`. More formally, if there are `k` elements after removing the duplicates, then the first `k` elements of `nums` should hold the final result. It does not matter what you leave beyond the first `k` elements.
8+
9+
Return `k` _after placing the final result in the first_ `k` _slots of_ `nums`.
10+
11+
Do **not** allocate extra space for another array. You must do this by **modifying the input array [in-place](https://en.wikipedia.org/wiki/In-place_algorithm)** with O(1) extra memory.
12+
13+
**Custom Judge:**
14+
15+
The judge will test your solution with the following code:
16+
17+
int[] nums = [...]; // Input array
18+
int[] expectedNums = [...]; // The expected answer with correct length
19+
20+
int k = removeDuplicates(nums); // Calls your implementation
21+
22+
assert k == expectedNums.length;
23+
for (int i = 0; i < k; i++) {
24+
assert nums[i] == expectedNums[i];
25+
}
26+
27+
If all assertions pass, then your solution will be **accepted**.
28+
29+
**Example 1:**
30+
31+
**Input:** nums = [1,1,1,2,2,3]
32+
33+
**Output:** 5, nums = [1,1,2,2,3,\_]
34+
35+
**Explanation:** Your function should return k = 5, with the first five elements of nums being 1, 1, 2, 2 and 3 respectively. It does not matter what you leave beyond the returned k (hence they are underscores).
36+
37+
**Example 2:**
38+
39+
**Input:** nums = [0,0,1,1,1,1,2,3,3]
40+
41+
**Output:** 7, nums = [0,0,1,1,2,3,3,\_,\_]
42+
43+
**Explanation:** Your function should return k = 7, with the first seven elements of nums being 0, 0, 1, 1, 2, 3 and 3 respectively. It does not matter what you leave beyond the returned k (hence they are underscores).
44+
45+
**Constraints:**
46+
47+
* <code>1 <= nums.length <= 3 * 10<sup>4</sup></code>
48+
* <code>-10<sup>4</sup> <= nums[i] <= 10<sup>4</sup></code>
49+
* `nums` is sorted in **non-decreasing** order.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// #Medium #Array #Two_Pointers #Udemy_Arrays #Top_Interview_150_Array/String
2+
// #2025_04_05_Time_40_ms_(99.63%)_Space_59.84_MB_(30.62%)
3+
4+
function removeDuplicates(nums: number[]): number {
5+
let i = 0
6+
let k = 0
7+
let count = 0
8+
while (i < nums.length - 1) {
9+
count++
10+
if (count <= 2) {
11+
nums[k++] = nums[i]
12+
}
13+
if (nums[i] !== nums[i + 1]) {
14+
count = 0
15+
}
16+
i++
17+
}
18+
count++
19+
if (count <= 2) {
20+
nums[k++] = nums[i]
21+
}
22+
return k
23+
}
24+
25+
export { removeDuplicates }
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
82\. Remove Duplicates from Sorted List II
2+
3+
Medium
4+
5+
Given the `head` of a sorted linked list, _delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list_. Return _the linked list **sorted** as well_.
6+
7+
**Example 1:**
8+
9+
![](https://assets.leetcode.com/uploads/2021/01/04/linkedlist1.jpg)
10+
11+
**Input:** head = [1,2,3,3,4,4,5]
12+
13+
**Output:** [1,2,5]
14+
15+
**Example 2:**
16+
17+
![](https://assets.leetcode.com/uploads/2021/01/04/linkedlist2.jpg)
18+
19+
**Input:** head = [1,1,1,2,3]
20+
21+
**Output:** [2,3]
22+
23+
**Constraints:**
24+
25+
* The number of nodes in the list is in the range `[0, 300]`.
26+
* `-100 <= Node.val <= 100`
27+
* The list is guaranteed to be **sorted** in ascending order.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// #Medium #Two_Pointers #Linked_List #Data_Structure_II_Day_11_Linked_List
2+
// #Algorithm_II_Day_3_Two_Pointers #Top_Interview_150_Linked_List
3+
// #2025_04_05_Time_0_ms_(100.00%)_Space_58.58_MB_(53.51%)
4+
5+
import { ListNode } from '../../com_github_leetcode/listnode'
6+
7+
/**
8+
* Definition for singly-linked list.
9+
* class ListNode {
10+
* val: number
11+
* next: ListNode | null
12+
* constructor(val?: number, next?: ListNode | null) {
13+
* this.val = (val===undefined ? 0 : val)
14+
* this.next = (next===undefined ? null : next)
15+
* }
16+
* }
17+
*/
18+
function deleteDuplicates(head: ListNode | null): ListNode | null {
19+
if (!head || !head.next) {
20+
return head
21+
}
22+
const dummy = new ListNode(0)
23+
dummy.next = head
24+
let prev: ListNode = dummy
25+
let curr: ListNode | null = head
26+
while (curr) {
27+
let hasDuplicate = false
28+
while (curr.next && curr.val === curr.next.val) {
29+
hasDuplicate = true
30+
curr = curr.next
31+
}
32+
if (hasDuplicate) {
33+
prev.next = curr.next
34+
} else {
35+
prev = prev.next!
36+
}
37+
curr = curr.next
38+
}
39+
return dummy.next
40+
}
41+
42+
export { deleteDuplicates }
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
86\. Partition List
2+
3+
Medium
4+
5+
Given the `head` of a linked list and a value `x`, partition it such that all nodes **less than** `x` come before nodes **greater than or equal** to `x`.
6+
7+
You should **preserve** the original relative order of the nodes in each of the two partitions.
8+
9+
**Example 1:**
10+
11+
![](https://assets.leetcode.com/uploads/2021/01/04/partition.jpg)
12+
13+
**Input:** head = [1,4,3,2,5,2], x = 3
14+
15+
**Output:** [1,2,2,4,3,5]
16+
17+
**Example 2:**
18+
19+
**Input:** head = [2,1], x = 2
20+
21+
**Output:** [1,2]
22+
23+
**Constraints:**
24+
25+
* The number of nodes in the list is in the range `[0, 200]`.
26+
* `-100 <= Node.val <= 100`
27+
* `-200 <= x <= 200`
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// #Medium #Two_Pointers #Linked_List #Top_Interview_150_Linked_List
2+
// #2025_04_05_Time_0_ms_(100.00%)_Space_58.16_MB_(62.07%)
3+
4+
import { ListNode } from '../../com_github_leetcode/listnode'
5+
6+
/**
7+
* Definition for singly-linked list.
8+
* class ListNode {
9+
* val: number
10+
* next: ListNode | null
11+
* constructor(val?: number, next?: ListNode | null) {
12+
* this.val = (val===undefined ? 0 : val)
13+
* this.next = (next===undefined ? null : next)
14+
* }
15+
* }
16+
*/
17+
function partition(head: ListNode | null, x: number): ListNode | null {
18+
let beforeHead = new ListNode(0)
19+
let afterHead = new ListNode(0)
20+
let before = beforeHead
21+
let after = afterHead
22+
while (head !== null) {
23+
const nextNode = head.next
24+
if (head.val < x) {
25+
before.next = head
26+
before = before.next
27+
} else {
28+
after.next = head
29+
after = after.next
30+
}
31+
head = nextNode
32+
}
33+
after.next = null
34+
before.next = afterHead.next
35+
return beforeHead.next
36+
}
37+
38+
export { partition }
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
88\. Merge Sorted Array
2+
3+
Easy
4+
5+
You are given two integer arrays `nums1` and `nums2`, sorted in **non-decreasing order**, and two integers `m` and `n`, representing the number of elements in `nums1` and `nums2` respectively.
6+
7+
**Merge** `nums1` and `nums2` into a single array sorted in **non-decreasing order**.
8+
9+
The final sorted array should not be returned by the function, but instead be _stored inside the array_ `nums1`. To accommodate this, `nums1` has a length of `m + n`, where the first `m` elements denote the elements that should be merged, and the last `n` elements are set to `0` and should be ignored. `nums2` has a length of `n`.
10+
11+
**Example 1:**
12+
13+
**Input:** nums1 = [1,2,3,0,0,0], m = 3, nums2 = [2,5,6], n = 3
14+
15+
**Output:** [1,2,2,3,5,6]
16+
17+
**Explanation:** The arrays we are merging are [1,2,3] and [2,5,6]. The result of the merge is [1,2,2,3,5,6] with the underlined elements coming from nums1.
18+
19+
**Example 2:**
20+
21+
**Input:** nums1 = [1], m = 1, nums2 = [], n = 0
22+
23+
**Output:** [1]
24+
25+
**Explanation:** The arrays we are merging are [1] and []. The result of the merge is [1].
26+
27+
**Example 3:**
28+
29+
**Input:** nums1 = [0], m = 0, nums2 = [1], n = 1
30+
31+
**Output:** [1]
32+
33+
**Explanation:** The arrays we are merging are [] and [1]. The result of the merge is [1]. Note that because m = 0, there are no elements in nums1. The 0 is only there to ensure the merge result can fit in nums1.
34+
35+
**Constraints:**
36+
37+
* `nums1.length == m + n`
38+
* `nums2.length == n`
39+
* `0 <= m, n <= 200`
40+
* `1 <= m + n <= 200`
41+
* <code>-10<sup>9</sup> <= nums1[i], nums2[j] <= 10<sup>9</sup></code>
42+
43+
**Follow up:** Can you come up with an algorithm that runs in `O(m + n)` time?
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// #Medium #Two_Pointers #Linked_List #Top_Interview_150_Linked_List
2+
// #2025_04_05_Time_0_ms_(100.00%)_Space_58.16_MB_(62.07%)
3+
4+
/**
5+
* Do not return anything, modify nums1 in-place instead.
6+
*/
7+
function merge(nums1: number[], m: number, nums2: number[], n: number): void {
8+
let i = m - 1
9+
let j = nums1.length - 1
10+
let p2 = n - 1
11+
while (p2 >= 0) {
12+
if (i >= 0 && nums1[i] > nums2[p2]) {
13+
nums1[j--] = nums1[i--]
14+
} else {
15+
nums1[j--] = nums2[p2--]
16+
}
17+
}
18+
}
19+
20+
export { merge }
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
92\. Reverse Linked List II
2+
3+
Medium
4+
5+
Given the `head` of a singly linked list and two integers `left` and `right` where `left <= right`, reverse the nodes of the list from position `left` to position `right`, and return _the reversed list_.
6+
7+
**Example 1:**
8+
9+
![](https://assets.leetcode.com/uploads/2021/02/19/rev2ex2.jpg)
10+
11+
**Input:** head = [1,2,3,4,5], left = 2, right = 4
12+
13+
**Output:** [1,4,3,2,5]
14+
15+
**Example 2:**
16+
17+
**Input:** head = [5], left = 1, right = 1
18+
19+
**Output:** [5]
20+
21+
**Constraints:**
22+
23+
* The number of nodes in the list is `n`.
24+
* `1 <= n <= 500`
25+
* `-500 <= Node.val <= 500`
26+
* `1 <= left <= right <= n`
27+
28+
**Follow up:** Could you do it in one pass?

0 commit comments

Comments
 (0)