🌐 AI搜索 & 代理 主页
Skip to content

Commit 98d32cf

Browse files
authored
Added tasks 6-20
1 parent 965748a commit 98d32cf

File tree

21 files changed

+911
-0
lines changed

21 files changed

+911
-0
lines changed

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
7171

7272
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
7373
|-|-|-|-|-|-
74+
| 0020 |[Valid Parentheses](src/main/c/g0001_0100/s0020_valid_parentheses/Solution.c)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
7475

7576
#### Day 10 Tree
7677

@@ -103,6 +104,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
103104

104105
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
105106
|-|-|-|-|-|-
107+
| 0015 |[3Sum](src/main/c/g0001_0100/s0015_3sum/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 47 | 87.75
106108

107109
#### Day 2 Array
108110

@@ -232,6 +234,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
232234

233235
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
234236
|-|-|-|-|-|-
237+
| 0019 |[Remove Nth Node From End of List](src/main/c/g0001_0100/s0019_remove_nth_node_from_end_of_list/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 0 | 100.00
235238

236239
#### Day 6 Sliding Window
237240

@@ -295,11 +298,13 @@ C-based LeetCode algorithm problem solutions, regularly updated.
295298

296299
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
297300
|-|-|-|-|-|-
301+
| 0015 |[3Sum](src/main/c/g0001_0100/s0015_3sum/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 47 | 87.75
298302

299303
#### Day 4 Two Pointers
300304

301305
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
302306
|-|-|-|-|-|-
307+
| 0011 |[Container With Most Water](src/main/c/g0001_0100/s0011_container_with_most_water/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
303308

304309
#### Day 5 Sliding Window
305310

@@ -335,6 +340,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
335340

336341
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
337342
|-|-|-|-|-|-
343+
| 0017 |[Letter Combinations of a Phone Number](src/main/c/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00
338344

339345
#### Day 12 Dynamic Programming
340346

@@ -1042,6 +1048,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
10421048

10431049
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10441050
|-|-|-|-|-|-
1051+
| 0019 |[Remove Nth Node From End of List](src/main/c/g0001_0100/s0019_remove_nth_node_from_end_of_list/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 0 | 100.00
10451052

10461053
#### Day 4 Linked List
10471054

@@ -1135,12 +1142,15 @@ C-based LeetCode algorithm problem solutions, regularly updated.
11351142

11361143
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11371144
|-|-|-|-|-|-
1145+
| 0007 |[Reverse Integer](src/main/c/g0001_0100/s0007_reverse_integer/Solution.c)| Medium | Top_Interview_Questions, Math | 0 | 100.00
1146+
| 0009 |[Palindrome Number](src/main/c/g0001_0100/s0009_palindrome_number/Solution.c)| Easy | Math | 0 | 100.00
11381147

11391148
#### Udemy Strings
11401149

11411150
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11421151
|-|-|-|-|-|-
11431152
| 0003 |[Longest Substring Without Repeating Characters](src/main/c/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1) | 15 | 29.93
1153+
| 0020 |[Valid Parentheses](src/main/c/g0001_0100/s0020_valid_parentheses/Solution.c)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
11441154
| 0005 |[Longest Palindromic Substring](src/main/c/g0001_0100/s0005_longest_palindromic_substring/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 2 | 97.74
11451155

11461156
#### Udemy Binary Search
@@ -1158,6 +1168,7 @@ C-based LeetCode algorithm problem solutions, regularly updated.
11581168

11591169
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11601170
|-|-|-|-|-|-
1171+
| 0015 |[3Sum](src/main/c/g0001_0100/s0015_3sum/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 47 | 87.75
11611172

11621173
#### Udemy Famous Algorithm
11631174

@@ -1198,11 +1209,13 @@ C-based LeetCode algorithm problem solutions, regularly updated.
11981209

11991210
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
12001211
|-|-|-|-|-|-
1212+
| 0010 |[Regular Expression Matching](src/main/c/g0001_0100/s0010_regular_expression_matching/Solution.c)| Hard | Top_Interview_Questions, String, Dynamic_Programming, Recursion, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00
12011213

12021214
#### Udemy Backtracking/Recursion
12031215

12041216
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
12051217
|-|-|-|-|-|-
1218+
| 0017 |[Letter Combinations of a Phone Number](src/main/c/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00
12061219

12071220
#### Udemy Bit Manipulation
12081221

@@ -1218,6 +1231,16 @@ C-based LeetCode algorithm problem solutions, regularly updated.
12181231

12191232
| # | Title | Difficulty | Tag | Time, ms | Time, %
12201233
|------|----------------|-------------|-------------|----------|---------
1234+
| 0020 |[Valid Parentheses](src/main/c/g0001_0100/s0020_valid_parentheses/Solution.c)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Data_Structure_I_Day_9_Stack_Queue, Udemy_Strings, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
1235+
| 0019 |[Remove Nth Node From End of List](src/main/c/g0001_0100/s0019_remove_nth_node_from_end_of_list/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Algorithm_I_Day_5_Two_Pointers, Level_2_Day_3_Linked_List, Big_O_Time_O(L)_Space_O(L) | 0 | 100.00
1236+
| 0017 |[Letter Combinations of a Phone Number](src/main/c/g0001_0100/s0017_letter_combinations_of_a_phone_number/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Algorithm_II_Day_11_Recursion_Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00
1237+
| 0015 |[3Sum](src/main/c/g0001_0100/s0015_3sum/Solution.c)| 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, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 47 | 87.75
1238+
| 0011 |[Container With Most Water](src/main/c/g0001_0100/s0011_container_with_most_water/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, Algorithm_II_Day_4_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
1239+
| 0010 |[Regular Expression Matching](src/main/c/g0001_0100/s0010_regular_expression_matching/Solution.c)| Hard | Top_Interview_Questions, String, Dynamic_Programming, Recursion, Udemy_Dynamic_Programming, Big_O_Time_O(m\*n)_Space_O(m\*n) | 0 | 100.00
1240+
| 0009 |[Palindrome Number](src/main/c/g0001_0100/s0009_palindrome_number/Solution.c)| Easy | Math, Udemy_Integers | 0 | 100.00
1241+
| 0008 |[String to Integer (atoi)](src/main/c/g0001_0100/s0008_string_to_integer_atoi/Solution.c)| Medium | Top_Interview_Questions, String | 0 | 100.00
1242+
| 0007 |[Reverse Integer](src/main/c/g0001_0100/s0007_reverse_integer/Solution.c)| Medium | Top_Interview_Questions, Math, Udemy_Integers | 0 | 100.00
1243+
| 0006 |[Zigzag Conversion](src/main/c/g0001_0100/s0006_zigzag_conversion/Solution.c)| Medium | String | 0 | 100.00
12211244
| 0005 |[Longest Palindromic Substring](src/main/c/g0001_0100/s0005_longest_palindromic_substring/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Data_Structure_II_Day_9_String, Algorithm_II_Day_14_Dynamic_Programming, Dynamic_Programming_I_Day_17, Udemy_Strings, Big_O_Time_O(n)_Space_O(n) | 2 | 97.74
12221245
| 0004 |[Median of Two Sorted Arrays](src/main/c/g0001_0100/s0004_median_of_two_sorted_arrays/Solution.c)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Divide_and_Conquer, Big_O_Time_O(log(min(N,M)))_Space_O(1) | 0 | 100.00
12231246
| 0003 |[Longest Substring Without Repeating Characters](src/main/c/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.c)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Algorithm_I_Day_6_Sliding_Window, Level_2_Day_14_Sliding_Window/Two_Pointer, Udemy_Strings, Big_O_Time_O(n)_Space_O(1) | 15 | 29.93
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
// #Medium #String #2024_10_28_Time_0_ms_(100.00%)_Space_8.6_MB_(83.33%)
2+
3+
#include <stdio.h>
4+
#include <stdlib.h>
5+
#include <string.h>
6+
7+
char* convert(const char* s, int numRows) {
8+
int sLen = strlen(s);
9+
if (numRows == 1) {
10+
// Return a copy of s since the function is expected to return a new string
11+
char* result = (char*)malloc((sLen + 1) * sizeof(char));
12+
strcpy(result, s);
13+
return result;
14+
}
15+
16+
int maxDist = numRows * 2 - 2;
17+
char* buf = (char*)malloc((sLen + 1) * sizeof(char));
18+
int bufIndex = 0; // Keeps track of current position in buffer
19+
20+
for (int i = 0; i < numRows; i++) {
21+
int index = i;
22+
if (i == 0 || i == numRows - 1) {
23+
// For the first and last rows
24+
while (index < sLen) {
25+
buf[bufIndex++] = s[index];
26+
index += maxDist;
27+
}
28+
} else {
29+
// For the middle rows
30+
while (index < sLen) {
31+
buf[bufIndex++] = s[index];
32+
index += maxDist - i * 2;
33+
if (index >= sLen) {
34+
break;
35+
}
36+
buf[bufIndex++] = s[index];
37+
index += i * 2;
38+
}
39+
}
40+
}
41+
42+
buf[bufIndex] = '\0';
43+
return buf;
44+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
6\. Zigzag Conversion
2+
3+
Medium
4+
5+
The string `"PAYPALISHIRING"` is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)
6+
7+
P A H N A P L S I I G Y I R
8+
9+
And then read line by line: `"PAHNAPLSIIGYIR"`
10+
11+
Write the code that will take a string and make this conversion given a number of rows:
12+
13+
string convert(string s, int numRows);
14+
15+
**Example 1:**
16+
17+
**Input:** s = "PAYPALISHIRING", numRows = 3
18+
19+
**Output:** "PAHNAPLSIIGYIR"
20+
21+
**Example 2:**
22+
23+
**Input:** s = "PAYPALISHIRING", numRows = 4
24+
25+
**Output:** "PINALSIGYAHRPI"
26+
27+
**Explanation:** P I N A L S I G Y A H R P I
28+
29+
**Example 3:**
30+
31+
**Input:** s = "A", numRows = 1
32+
33+
**Output:** "A"
34+
35+
**Constraints:**
36+
37+
* `1 <= s.length <= 1000`
38+
* `s` consists of English letters (lower-case and upper-case), `','` and `'.'`.
39+
* `1 <= numRows <= 1000`
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// #Medium #Top_Interview_Questions #Math #Udemy_Integers
2+
// #2024_10_28_Time_0_ms_(100.00%)_Space_8.3_MB_(93.52%)
3+
4+
int reverse(int x) {
5+
long rev = 0;
6+
while (x != 0) {
7+
rev = (rev * 10) + (x % 10);
8+
x /= 10;
9+
}
10+
11+
// Check for overflow
12+
if (rev > INT_MAX || rev < INT_MIN) {
13+
return 0;
14+
}
15+
16+
return (int)rev;
17+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
7\. Reverse Integer
2+
3+
Medium
4+
5+
Given a signed 32-bit integer `x`, return `x` _with its digits reversed_. If reversing `x` causes the value to go outside the signed 32-bit integer range <code>[-2<sup>31</sup>, 2<sup>31</sup> - 1]</code>, then return `0`.
6+
7+
**Assume the environment does not allow you to store 64-bit integers (signed or unsigned).**
8+
9+
**Example 1:**
10+
11+
**Input:** x = 123
12+
13+
**Output:** 321
14+
15+
**Example 2:**
16+
17+
**Input:** x = -123
18+
19+
**Output:** -321
20+
21+
**Example 3:**
22+
23+
**Input:** x = 120
24+
25+
**Output:** 21
26+
27+
**Example 4:**
28+
29+
**Input:** x = 0
30+
31+
**Output:** 0
32+
33+
**Constraints:**
34+
35+
* <code>-2<sup>31</sup> <= x <= 2<sup>31</sup> - 1</code>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// #Medium #Top_Interview_Questions #String #2024_10_28_Time_0_ms_(100.00%)_Space_8.5_MB_(69.69%)
2+
3+
#include <stdio.h>
4+
#include <limits.h>
5+
#include <ctype.h>
6+
7+
int myAtoi(const char* str) {
8+
if (str == NULL || *str == '\0') {
9+
return 0;
10+
}
11+
12+
int i = 0;
13+
int num = 0;
14+
int negativeSign = 0;
15+
16+
// Skip leading whitespace
17+
while (str[i] == ' ') {
18+
i++;
19+
}
20+
21+
// Check for sign
22+
if (str[i] == '+') {
23+
i++;
24+
} else if (str[i] == '-') {
25+
i++;
26+
negativeSign = 1;
27+
}
28+
29+
// Convert string to integer
30+
while (str[i] >= '0' && str[i] <= '9') {
31+
int digit = str[i] - '0';
32+
33+
if (negativeSign) {
34+
digit = -digit;
35+
}
36+
37+
// Handle overflow and underflow
38+
if (num < INT_MIN / 10 || (num == INT_MIN / 10 && digit < -8)) {
39+
return INT_MIN;
40+
}
41+
if (num > INT_MAX / 10 || (num == INT_MAX / 10 && digit > 7)) {
42+
return INT_MAX;
43+
}
44+
45+
num = num * 10 + digit;
46+
i++;
47+
}
48+
49+
return num;
50+
}

0 commit comments

Comments
 (0)