Skip to content

Commit aacba4a

Browse files
authored
Added tasks 12-28
1 parent 0bcae35 commit aacba4a

File tree

19 files changed

+557
-0
lines changed

19 files changed

+557
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
524524

525525
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
526526
|-|-|-|-|-|-
527+
| 0028 |[Implement strStr()](src/main/ts/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/solution.ts)| Easy | Top_Interview_Questions, String, Two_Pointers, String_Matching | 0 | 100.00
527528

528529
#### Day 2
529530

@@ -852,6 +853,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
852853

853854
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
854855
|-|-|-|-|-|-
856+
| 0014 |[Longest Common Prefix](src/main/ts/g0001_0100/s0014_longest_common_prefix/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String | 0 | 100.00
855857

856858
#### Day 3 Linked List
857859

@@ -978,6 +980,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
978980

979981
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
980982
|-|-|-|-|-|-
983+
| 0014 |[Longest Common Prefix](src/main/ts/g0001_0100/s0014_longest_common_prefix/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String | 0 | 100.00
981984
| 0003 |[Longest Substring Without Repeating Characters](src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1), AI_can_be_used_to_solve_the_task | 3 | 96.91
982985
| 0020 |[Valid Parentheses](src/main/ts/g0001_0100/s0020_valid_parentheses/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 1 | 86.85
983986
| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 8 | 99.14
@@ -1009,6 +1012,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
10091012

10101013
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10111014
|-|-|-|-|-|-
1015+
| 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
10121016
| 0042 |[Trapping Rain Water](src/main/ts/g0001_0100/s0042_trapping_rain_water/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
10131017
| 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
10141018

@@ -1116,14 +1120,20 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
11161120

11171121
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11181122
|-|-|-|-|-|-
1123+
| 0027 |[Remove Element](src/main/ts/g0001_0100/s0027_remove_element/solution.ts)| Easy | Array, Two_Pointers | 0 | 100.00
1124+
| 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
11191125
| 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
11201126
| 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
11211127
| 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
11221128
| 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
11231129
| 0045 |[Jump Game II](src/main/ts/g0001_0100/s0045_jump_game_ii/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 1 | 84.27
11241130
| 0238 |[Product of Array Except Self](src/main/ts/g0201_0300/s0238_product_of_array_except_self/solution.ts)| Medium | Top_100_Liked_Questions, Array, Prefix_Sum, Big_O_Time_O(n^2)_Space_O(n) | 3 | 92.81
11251131
| 0042 |[Trapping Rain Water](src/main/ts/g0001_0100/s0042_trapping_rain_water/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
1132+
| 0013 |[Roman to Integer](src/main/ts/g0001_0100/s0013_roman_to_integer/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Math | 3 | 94.58
1133+
| 0012 |[Integer to Roman](src/main/ts/g0001_0100/s0012_integer_to_roman/solution.ts)| Medium | String, Hash_Table, Math | 3 | 93.02
1134+
| 0014 |[Longest Common Prefix](src/main/ts/g0001_0100/s0014_longest_common_prefix/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String | 0 | 100.00
11261135
| 0006 |[Zigzag Conversion](src/main/ts/g0001_0100/s0006_zigzag_conversion/solution.ts)| Medium | String | 2 | 99.08
1136+
| 0028 |[Implement strStr()](src/main/ts/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/solution.ts)| Easy | Top_Interview_Questions, String, Two_Pointers, String_Matching | 0 | 100.00
11271137

11281138
#### Top Interview 150 Two Pointers
11291139

@@ -1681,6 +1691,9 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
16811691
| 0033 |[Search in Rotated Sorted Array](src/main/ts/g0001_0100/s0033_search_in_rotated_sorted_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Algorithm_II_Day_1_Binary_Search, Binary_Search_I_Day_11, Level_2_Day_8_Binary_Search, Udemy_Binary_Search, Top_Interview_150_Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
16821692
| 0032 |[Longest Valid Parentheses](src/main/ts/g0001_0100/s0032_longest_valid_parentheses/solution.ts)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Stack, Big_O_Time_O(n)_Space_O(1) | 3 | 71.05
16831693
| 0031 |[Next Permutation](src/main/ts/g0001_0100/s0031_next_permutation/solution.ts)| Medium | Top_100_Liked_Questions, Array, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
1694+
| 0028 |[Implement strStr()](src/main/ts/g0001_0100/s0028_find_the_index_of_the_first_occurrence_in_a_string/solution.ts)| Easy | Top_Interview_Questions, String, Two_Pointers, String_Matching, Programming_Skills_II_Day_1, Top_Interview_150_Array/String | 0 | 100.00
1695+
| 0027 |[Remove Element](src/main/ts/g0001_0100/s0027_remove_element/solution.ts)| Easy | Array, Two_Pointers, Top_Interview_150_Array/String | 0 | 100.00
1696+
| 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, Udemy_Two_Pointers, Top_Interview_150_Array/String | 0 | 100.00
16841697
| 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, Data_Structure_II_Day_13_Linked_List, Udemy_Linked_List, Top_Interview_150_Linked_List, Big_O_Time_O(n)_Space_O(k) | 0 | 100.00
16851698
| 0024 |[Swap Nodes in Pairs](src/main/ts/g0001_0100/s0024_swap_nodes_in_pairs/solution.ts)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Data_Structure_II_Day_12_Linked_List, Udemy_Linked_List, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
16861699
| 0023 |[Merge k Sorted Lists](src/main/ts/g0001_0100/s0023_merge_k_sorted_lists/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Heap_Priority_Queue, Linked_List, Divide_and_Conquer, Merge_Sort, Top_Interview_150_Divide_and_Conquer, Big_O_Time_O(k\*n\*log(k))_Space_O(log(k)) | 4 | 97.65
@@ -1690,6 +1703,9 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
16901703
| 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, Algorithm_I_Day_5_Two_Pointers, Level_2_Day_3_Linked_List, Top_Interview_150_Linked_List, Big_O_Time_O(L)_Space_O(L) | 0 | 100.00
16911704
| 0017 |[Letter Combinations of a Phone Number](src/main/ts/g0001_0100/s0017_letter_combinations_of_a_phone_number/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Algorithm_II_Day_11_Recursion_Backtracking, Udemy_Backtracking/Recursion, Top_Interview_150_Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00
16921705
| 0015 |[3Sum](src/main/ts/g0001_0100/s0015_3sum/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Data_Structure_II_Day_1_Array, Algorithm_II_Day_3_Two_Pointers, Udemy_Two_Pointers, Top_Interview_150_Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 30 | 91.56
1706+
| 0014 |[Longest Common Prefix](src/main/ts/g0001_0100/s0014_longest_common_prefix/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Level_2_Day_2_String, Udemy_Strings, Top_Interview_150_Array/String | 0 | 100.00
1707+
| 0013 |[Roman to Integer](src/main/ts/g0001_0100/s0013_roman_to_integer/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Math, Top_Interview_150_Array/String | 3 | 94.58
1708+
| 0012 |[Integer to Roman](src/main/ts/g0001_0100/s0012_integer_to_roman/solution.ts)| Medium | String, Hash_Table, Math, Top_Interview_150_Array/String | 3 | 93.02
16931709
| 0011 |[Container With Most Water](src/main/ts/g0001_0100/s0011_container_with_most_water/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, Algorithm_II_Day_4_Two_Pointers, Top_Interview_150_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 2 | 80.13
16941710
| 0010 |[Regular Expression Matching](src/main/ts/g0001_0100/s0010_regular_expression_matching/solution.ts)| Hard | Top_Interview_Questions, String, Dynamic_Programming, Recursion, Udemy_Dynamic_Programming, Big_O_Time_O(m\*n)_Space_O(m\*n) | 5 | 90.44
16951711
| 0009 |[Palindrome Number](src/main/ts/g0001_0100/s0009_palindrome_number/solution.ts)| Easy | Math, Udemy_Integers, Top_Interview_150_Math | 3 | 99.14
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
12\. Integer to Roman
2+
3+
Medium
4+
5+
Roman numerals are represented by seven different symbols: `I`, `V`, `X`, `L`, `C`, `D` and `M`.
6+
7+
Symbol Value
8+
I 1
9+
V 5
10+
X 10
11+
L 50
12+
C 100
13+
D 500
14+
M 1000
15+
16+
For example, `2` is written as `II` in Roman numeral, just two one's added together. `12` is written as `XII`, which is simply `X + II`. The number `27` is written as `XXVII`, which is `XX + V + II`.
17+
18+
Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not `IIII`. Instead, the number four is written as `IV`. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as `IX`. There are six instances where subtraction is used:
19+
20+
* `I` can be placed before `V` (5) and `X` (10) to make 4 and 9.
21+
* `X` can be placed before `L` (50) and `C` (100) to make 40 and 90.
22+
* `C` can be placed before `D` (500) and `M` (1000) to make 400 and 900.
23+
24+
Given an integer, convert it to a roman numeral.
25+
26+
**Example 1:**
27+
28+
**Input:** num = 3
29+
30+
**Output:** "III"
31+
32+
**Example 2:**
33+
34+
**Input:** num = 4
35+
36+
**Output:** "IV"
37+
38+
**Example 3:**
39+
40+
**Input:** num = 9
41+
42+
**Output:** "IX"
43+
44+
**Example 4:**
45+
46+
**Input:** num = 58
47+
48+
**Output:** "LVIII"
49+
50+
**Explanation:** L = 50, V = 5, III = 3.
51+
52+
**Example 5:**
53+
54+
**Input:** num = 1994
55+
56+
**Output:** "MCMXCIV"
57+
58+
**Explanation:** M = 1000, CM = 900, XC = 90 and IV = 4.
59+
60+
**Constraints:**
61+
62+
* `1 <= num <= 3999`
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// #Medium #String #Hash_Table #Math #Top_Interview_150_Array/String
2+
// #2025_03_31_Time_3_ms_(93.02%)_Space_61.86_MB_(54.05%)
3+
4+
function intToRoman(num: number): string {
5+
const values = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
6+
const symbols = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"];
7+
8+
let result = "";
9+
let i = 0;
10+
11+
while (num > 0) {
12+
if (num >= values[i]) {
13+
result += symbols[i];
14+
num -= values[i];
15+
} else {
16+
i++;
17+
}
18+
}
19+
20+
return result;
21+
};
22+
23+
export { intToRoman }
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
13\. Roman to Integer
2+
3+
Easy
4+
5+
Roman numerals are represented by seven different symbols: `I`, `V`, `X`, `L`, `C`, `D` and `M`.
6+
7+
Symbol Value
8+
I 1
9+
V 5
10+
X 10
11+
L 50
12+
C 100
13+
D 500
14+
M 1000
15+
16+
For example, `2` is written as `II` in Roman numeral, just two one's added together. `12` is written as `XII`, which is simply `X + II`. The number `27` is written as `XXVII`, which is `XX + V + II`.
17+
18+
Roman numerals are usually written largest to smallest from left to right. However, the numeral for four is not `IIII`. Instead, the number four is written as `IV`. Because the one is before the five we subtract it making four. The same principle applies to the number nine, which is written as `IX`. There are six instances where subtraction is used:
19+
20+
* `I` can be placed before `V` (5) and `X` (10) to make 4 and 9.
21+
* `X` can be placed before `L` (50) and `C` (100) to make 40 and 90.
22+
* `C` can be placed before `D` (500) and `M` (1000) to make 400 and 900.
23+
24+
Given a roman numeral, convert it to an integer.
25+
26+
**Example 1:**
27+
28+
**Input:** s = "III"
29+
30+
**Output:** 3
31+
32+
**Example 2:**
33+
34+
**Input:** s = "IV"
35+
36+
**Output:** 4
37+
38+
**Example 3:**
39+
40+
**Input:** s = "IX"
41+
42+
**Output:** 9
43+
44+
**Example 4:**
45+
46+
**Input:** s = "LVIII"
47+
48+
**Output:** 58
49+
50+
**Explanation:** L = 50, V= 5, III = 3.
51+
52+
**Example 5:**
53+
54+
**Input:** s = "MCMXCIV"
55+
56+
**Output:** 1994
57+
58+
**Explanation:** M = 1000, CM = 900, XC = 90 and IV = 4.
59+
60+
**Constraints:**
61+
62+
* `1 <= s.length <= 15`
63+
* `s` contains only the characters `('I', 'V', 'X', 'L', 'C', 'D', 'M')`.
64+
* It is **guaranteed** that `s` is a valid roman numeral in the range `[1, 3999]`.
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Math
2+
// #Top_Interview_150_Array/String #2025_03_31_Time_3_ms_(94.58%)_Space_61.52_MB_(51.93%)
3+
4+
function romanToInt(s: string): number {
5+
let x = 0;
6+
let y: string;
7+
8+
for (let i = 0; i < s.length; i++) {
9+
y = s.charAt(i);
10+
switch (y) {
11+
case 'I':
12+
x = getX(s, x, i, 1, 'V', 'X');
13+
break;
14+
case 'V':
15+
x += 5;
16+
break;
17+
case 'X':
18+
x = getX(s, x, i, 10, 'L', 'C');
19+
break;
20+
case 'L':
21+
x += 50;
22+
break;
23+
case 'C':
24+
x = getX(s, x, i, 100, 'D', 'M');
25+
break;
26+
case 'D':
27+
x += 500;
28+
break;
29+
case 'M':
30+
x += 1000;
31+
break;
32+
default:
33+
break;
34+
}
35+
}
36+
return x;
37+
}
38+
39+
function getX(s: string, x: number, i: number, i2: number, v: string, x2: string): number {
40+
if (i + 1 === s.length) {
41+
x += i2;
42+
} else if (s.charAt(i + 1) === v || s.charAt(i + 1) === x2) {
43+
x -= i2;
44+
} else {
45+
x += i2;
46+
}
47+
return x;
48+
}
49+
50+
51+
export { romanToInt }
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
14\. Longest Common Prefix
2+
3+
Easy
4+
5+
Write a function to find the longest common prefix string amongst an array of strings.
6+
7+
If there is no common prefix, return an empty string `""`.
8+
9+
**Example 1:**
10+
11+
**Input:** strs = ["flower","flow","flight"]
12+
13+
**Output:** "fl"
14+
15+
**Example 2:**
16+
17+
**Input:** strs = ["dog","racecar","car"]
18+
19+
**Output:** ""
20+
21+
**Explanation:** There is no common prefix among the input strings.
22+
23+
**Constraints:**
24+
25+
* `1 <= strs.length <= 200`
26+
* `0 <= strs[i].length <= 200`
27+
* `strs[i]` consists of only lower-case English letters.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// #Easy #Top_100_Liked_Questions #Top_Interview_Questions #String #Level_2_Day_2_String
2+
// #Udemy_Strings #Top_Interview_150_Array/String
3+
// #2025_03_31_Time_0_ms_(100.00%)_Space_54.23_MB_(65.24%)
4+
5+
function longestCommonPrefix(strs: string[]): string {
6+
if (strs.length < 1) {
7+
return "";
8+
}
9+
if (strs.length === 1) {
10+
return strs[0];
11+
}
12+
let temp = strs[0];
13+
let i = 1;
14+
let cur: string;
15+
while (temp.length > 0 && i < strs.length) {
16+
if (temp.length > strs[i].length) {
17+
temp = temp.substring(0, strs[i].length);
18+
}
19+
cur = strs[i].substring(0, temp.length);
20+
if (cur !== temp) {
21+
temp = temp.substring(0, temp.length - 1);
22+
} else {
23+
i++;
24+
}
25+
}
26+
return temp;
27+
}
28+
29+
export { longestCommonPrefix }
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
26\. Remove Duplicates from Sorted Array
2+
3+
Easy
4+
5+
Given an integer array `nums` sorted in **non-decreasing order**, remove the duplicates [**in-place**](https://en.wikipedia.org/wiki/In-place_algorithm) such that each unique element appears only **once**. 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,2]
32+
33+
**Output:** 2, nums = [1,2,\_]
34+
35+
**Explanation:** Your function should return k = 2, with the first two elements of nums being 1 and 2 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,2,2,3,3,4]
40+
41+
**Output:** 5, nums = [0,1,2,3,4,\_,\_,\_,\_,\_]
42+
43+
**Explanation:** Your function should return k = 5, with the first five elements of nums being 0, 1, 2, 3, and 4 respectively. It does not matter what you leave beyond the returned k (hence they are underscores).
44+
45+
**Constraints:**
46+
47+
* <code>0 <= nums.length <= 3 * 10<sup>4</sup></code>
48+
* `-100 <= nums[i] <= 100`
49+
* `nums` is sorted in **non-decreasing** order.

0 commit comments

Comments
 (0)