Skip to content

Commit 9036231

Browse files
authored
Added tasks 9, 10
1 parent b287acb commit 9036231

File tree

6 files changed

+195
-34
lines changed

6 files changed

+195
-34
lines changed

README.md

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
3030
|-|-|-|-|-|-
31-
| 0001 |[Two Sum](src/main/ts/g0001_0100/s0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table | 66 | 93.20
31+
| 0001 |[Two Sum](src/main/ts/g0001_0100/s0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table | 51 | 97.89
3232

3333
#### Day 3 Array
3434

@@ -136,13 +136,13 @@
136136

137137
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
138138
|-|-|-|-|-|-
139-
| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming | 660 | 36.76
139+
| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming | 480 | 35.37
140140

141141
#### Day 10 Linked List
142142

143143
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
144144
|-|-|-|-|-|-
145-
| 0002 |[Add Two Numbers](src/main/ts/g0001_0100/s0002_add_two_numbers)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion | 106 | 79.11
145+
| 0002 |[Add Two Numbers](src/main/ts/g0001_0100/s0002_add_two_numbers)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion | 88 | 93.29
146146

147147
#### Day 11 Linked List
148148

@@ -230,7 +230,7 @@
230230

231231
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
232232
|-|-|-|-|-|-
233-
| 0003 |[Longest Substring Without Repeating Characters](src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window | 95 | 70.71
233+
| 0003 |[Longest Substring Without Repeating Characters](src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window | 81 | 68.46
234234

235235
#### Day 7 Breadth First Search Depth First Search
236236

@@ -343,7 +343,7 @@
343343

344344
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
345345
|-|-|-|-|-|-
346-
| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming | 660 | 36.76
346+
| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming | 480 | 35.37
347347

348348
#### Day 15 Dynamic Programming
349349

@@ -630,7 +630,7 @@
630630

631631
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
632632
|-|-|-|-|-|-
633-
| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming | 660 | 36.76
633+
| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming | 480 | 35.37
634634

635635
#### Day 18
636636

@@ -790,7 +790,7 @@
790790

791791
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
792792
|-|-|-|-|-|-
793-
| 0002 |[Add Two Numbers](src/main/ts/g0001_0100/s0002_add_two_numbers)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion | 106 | 79.11
793+
| 0002 |[Add Two Numbers](src/main/ts/g0001_0100/s0002_add_two_numbers)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion | 88 | 93.29
794794

795795
#### Day 16
796796

@@ -1007,7 +1007,7 @@
10071007

10081008
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10091009
|-|-|-|-|-|-
1010-
| 0001 |[Two Sum](src/main/ts/g0001_0100/s0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table | 66 | 93.20
1010+
| 0001 |[Two Sum](src/main/ts/g0001_0100/s0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table | 51 | 97.89
10111011

10121012
#### Day 14 Stack
10131013

@@ -1090,7 +1090,7 @@
10901090

10911091
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10921092
|-|-|-|-|-|-
1093-
| 0003 |[Longest Substring Without Repeating Characters](src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window | 95 | 70.71
1093+
| 0003 |[Longest Substring Without Repeating Characters](src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window | 81 | 68.46
10941094

10951095
#### Day 15 Tree
10961096

@@ -1129,13 +1129,14 @@
11291129
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11301130
|-|-|-|-|-|-
11311131
| 0007 |[Reverse Integer](src/main/ts/g0001_0100/s0007_reverse_integer)| Medium | Top_Interview_Questions, Math | 56 | 95.68
1132+
| 0009 |[Palindrome Number](src/main/ts/g0001_0100/s0009_palindrome_number)| Easy | Math | 137 | 88.64
11321133

11331134
#### Udemy Strings
11341135

11351136
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11361137
|-|-|-|-|-|-
1137-
| 0003 |[Longest Substring Without Repeating Characters](src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window | 95 | 70.71
1138-
| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming | 660 | 36.76
1138+
| 0003 |[Longest Substring Without Repeating Characters](src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window | 81 | 68.46
1139+
| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming | 480 | 35.37
11391140

11401141
#### Udemy Binary Search
11411142

@@ -1146,7 +1147,7 @@
11461147

11471148
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11481149
|-|-|-|-|-|-
1149-
| 0001 |[Two Sum](src/main/ts/g0001_0100/s0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table | 66 | 93.20
1150+
| 0001 |[Two Sum](src/main/ts/g0001_0100/s0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table | 51 | 97.89
11501151

11511152
#### Udemy Two Pointers
11521153

@@ -1192,6 +1193,7 @@
11921193

11931194
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11941195
|-|-|-|-|-|-
1196+
| 0010 |[Regular Expression Matching](src/main/ts/g0001_0100/s0010_regular_expression_matching)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Recursion | 69 | 92.65
11951197

11961198
#### Udemy Backtracking/Recursion
11971199

@@ -1212,12 +1214,14 @@
12121214

12131215
| # | Title | Difficulty | Tag | Time, ms | Time, %
12141216
|------|----------------|-------------|-------------|----------|--------
1217+
| 0010 |[Regular Expression Matching](src/main/ts/g0001_0100/s0010_regular_expression_matching)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Recursion, Udemy_Dynamic_Programming | 69 | 92.65
1218+
| 0009 |[Palindrome Number](src/main/ts/g0001_0100/s0009_palindrome_number)| Easy | Math, Udemy_Integers | 137 | 88.64
12151219
| 0008 |[String to Integer (atoi)](src/main/ts/g0001_0100/s0008_string_to_integer_atoi)| Medium | Top_Interview_Questions, String | 56 | 99.01
12161220
| 0007 |[Reverse Integer](src/main/ts/g0001_0100/s0007_reverse_integer)| Medium | Top_Interview_Questions, Math, Udemy_Integers | 56 | 95.68
1217-
| 0006 |[Zigzag Conversion](src/main/ts/g0001_0100/s0006_zigzag_conversion)| Medium | String | 80 | 93.13
1218-
| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring)| 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 | 660 | 36.76
1219-
| 0004 |[Median of Two Sorted Arrays](src/main/ts/g0001_0100/s0004_median_of_two_sorted_arrays)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Divide_and_Conquer | 93 | 97.16
1220-
| 0003 |[Longest Substring Without Repeating Characters](src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters)| 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 | 95 | 70.71
1221-
| 0002 |[Add Two Numbers](src/main/ts/g0001_0100/s0002_add_two_numbers)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Data_Structure_II_Day_10_Linked_List, Programming_Skills_II_Day_15 | 106 | 79.11
1222-
| 0001 |[Two Sum](src/main/ts/g0001_0100/s0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Data_Structure_I_Day_2_Array, Level_1_Day_13_Hashmap, Udemy_Arrays | 66 | 93.20
1221+
| 0006 |[Zigzag Conversion](src/main/ts/g0001_0100/s0006_zigzag_conversion)| Medium | String | 64 | 95.38
1222+
| 0005 |[Longest Palindromic Substring](src/main/ts/g0001_0100/s0005_longest_palindromic_substring)| 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 | 480 | 35.37
1223+
| 0004 |[Median of Two Sorted Arrays](src/main/ts/g0001_0100/s0004_median_of_two_sorted_arrays)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Divide_and_Conquer | 86 | 92.15
1224+
| 0003 |[Longest Substring Without Repeating Characters](src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters)| 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 | 81 | 68.46
1225+
| 0002 |[Add Two Numbers](src/main/ts/g0001_0100/s0002_add_two_numbers)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Math, Linked_List, Recursion, Data_Structure_II_Day_10_Linked_List, Programming_Skills_II_Day_15 | 88 | 93.29
1226+
| 0001 |[Two Sum](src/main/ts/g0001_0100/s0001_two_sum)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Data_Structure_I_Day_2_Array, Level_1_Day_13_Hashmap, Udemy_Arrays | 51 | 97.89
12231227

src/main/ts/g0001_0100/s0001_two_sum/readme.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,28 @@ You can return the answer in any order.
1717

1818
**Output:** [0,1]
1919

20-
**Output:** Because nums[0] + nums[1] == 9, we return [0, 1].
20+
**Explanation:** Because nums[0] + nums[1] == 9, we return [0, 1].
2121

2222
**Example 2:**
2323

2424
**Input:** nums = [3,2,4], target = 6
2525

26-
**Output:** [1,2]
26+
**Output:** [1,2]
2727

2828
**Example 3:**
2929

3030
**Input:** nums = [3,3], target = 6
3131

32-
**Output:** [0,1]
32+
**Output:** [0,1]
3333

3434
**Constraints:**
3535

36-
- <code>2 <= nums.length <= 10<sup>4</sup></code>
37-
- <code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code>
38-
- <code>-10<sup>9</sup> <= target <= 10<sup>9</sup></code>
39-
- **Only one valid answer exists.**
36+
* <code>2 <= nums.length <= 10<sup>4</sup></code>
37+
* <code>-10<sup>9</sup> <= nums[i] <= 10<sup>9</sup></code>
38+
* <code>-10<sup>9</sup> <= target <= 10<sup>9</sup></code>
39+
* **Only one valid answer exists.**
4040

41-
**Follow-up:** Can you come up with an algorithm that is less than <code>O(n<sup>2</sup>) </code>time complexity?
41+
**Follow-up:** Can you come up with an algorithm that is less than <code>O(n<sup>2</sup>)</code> time complexity?
4242

4343
## Solution
4444

src/main/ts/g0001_0100/s0002_add_two_numbers/readme.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,25 +17,25 @@ You may assume the two numbers do not contain any leading zero, except the numbe
1717

1818
**Output:** [7,0,8]
1919

20-
**Explanation:** 342 + 465 = 807.
20+
**Explanation:** 342 + 465 = 807.
2121

2222
**Example 2:**
2323

2424
**Input:** l1 = [0], l2 = [0]
2525

26-
**Output:** [0]
26+
**Output:** [0]
2727

2828
**Example 3:**
2929

3030
**Input:** l1 = [9,9,9,9,9,9,9], l2 = [9,9,9,9]
3131

32-
**Output:** [8,9,9,9,0,0,0,1]
32+
**Output:** [8,9,9,9,0,0,0,1]
3333

3434
**Constraints:**
3535

36-
- The number of nodes in each linked list is in the range `[1, 100]`.
37-
- `0 <= Node.val <= 9`
38-
- It is guaranteed that the list represents a number that does not have leading zeros.
36+
* The number of nodes in each linked list is in the range `[1, 100]`.
37+
* `0 <= Node.val <= 9`
38+
* It is guaranteed that the list represents a number that does not have leading zeros.
3939

4040
## Solution
4141

src/main/ts/g0001_0100/s0003_longest_substring_without_repeating_characters/readme.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ Given a string `s`, find the length of the **longest** **substring** without rep
2929

3030
**Output:** 3
3131

32-
**Explanation:** The answer is "wke", with the length of 3.
32+
**Explanation:**
33+
34+
The answer is "wke", with the length of 3.
3335

3436
Notice that the answer must be a substring, "pwke" is a subsequence and not a substring.
3537

@@ -46,7 +48,6 @@ function lengthOfLongestSubstring(s: string): number {
4648
let maxLength = 0
4749
let length = 0
4850
let start = 0
49-
5051
for (let i = 0; i < s.length; i++) {
5152
const char = s[i]
5253
if (hash[char] !== undefined && hash[char] >= start) {
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
[![](https://img.shields.io/github/stars/LeetCode-in-TypeScript/LeetCode-in-TypeScript?label=Stars&style=flat-square)](https://github.com/LeetCode-in-TypeScript/LeetCode-in-TypeScript)
2+
[![](https://img.shields.io/github/forks/LeetCode-in-TypeScript/LeetCode-in-TypeScript?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-TypeScript/LeetCode-in-TypeScript/fork)
3+
4+
## 9\. Palindrome Number
5+
6+
Easy
7+
8+
Given an integer `x`, return `true` if `x` is palindrome integer.
9+
10+
An integer is a **palindrome** when it reads the same backward as forward. For example, `121` is palindrome while `123` is not.
11+
12+
**Example 1:**
13+
14+
**Input:** x = 121
15+
16+
**Output:** true
17+
18+
**Example 2:**
19+
20+
**Input:** x = -121
21+
22+
**Output:** false
23+
24+
**Explanation:** From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
25+
26+
**Example 3:**
27+
28+
**Input:** x = 10
29+
30+
**Output:** false
31+
32+
**Explanation:** Reads 01 from right to left. Therefore it is not a palindrome.
33+
34+
**Example 4:**
35+
36+
**Input:** x = -101
37+
38+
**Output:** false
39+
40+
**Constraints:**
41+
42+
* <code>-2<sup>31</sup> <= x <= 2<sup>31</sup> - 1</code>
43+
44+
**Follow up:** Could you solve it without converting the integer to a string?
45+
46+
## Solution
47+
48+
```typescript
49+
function isPalindrome(x: number): boolean {
50+
if (x < 0) {
51+
return false
52+
}
53+
let rev: number = 0
54+
let localX: number = x
55+
while (localX > 0) {
56+
rev *= 10
57+
rev += localX % 10
58+
localX = Math.floor(localX / 10)
59+
}
60+
return rev === x
61+
}
62+
63+
export { isPalindrome }
64+
```
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
[![](https://img.shields.io/github/stars/LeetCode-in-TypeScript/LeetCode-in-TypeScript?label=Stars&style=flat-square)](https://github.com/LeetCode-in-TypeScript/LeetCode-in-TypeScript)
2+
[![](https://img.shields.io/github/forks/LeetCode-in-TypeScript/LeetCode-in-TypeScript?label=Fork%20me%20on%20GitHub%20&style=flat-square)](https://github.com/LeetCode-in-TypeScript/LeetCode-in-TypeScript/fork)
3+
4+
## 10\. Regular Expression Matching
5+
6+
Hard
7+
8+
Given an input string `s` and a pattern `p`, implement regular expression matching with support for `'.'` and `'*'` where:
9+
10+
* `'.'` Matches any single character.
11+
* `'*'` Matches zero or more of the preceding element.
12+
13+
The matching should cover the **entire** input string (not partial).
14+
15+
**Example 1:**
16+
17+
**Input:** s = "aa", p = "a"
18+
19+
**Output:** false
20+
21+
**Explanation:** "a" does not match the entire string "aa".
22+
23+
**Example 2:**
24+
25+
**Input:** s = "aa", p = "a\*"
26+
27+
**Output:** true
28+
29+
**Explanation:** '\*' means zero or more of the preceding element, 'a'. Therefore, by repeating 'a' once, it becomes "aa".
30+
31+
**Example 3:**
32+
33+
**Input:** s = "ab", p = ".\*"
34+
35+
**Output:** true
36+
37+
**Explanation:** ".\*" means "zero or more (\*) of any character (.)".
38+
39+
**Example 4:**
40+
41+
**Input:** s = "aab", p = "c\*a\*b"
42+
43+
**Output:** true
44+
45+
**Explanation:** c can be repeated 0 times, a can be repeated 1 time. Therefore, it matches "aab".
46+
47+
**Example 5:**
48+
49+
**Input:** s = "mississippi", p = "mis\*is\*p\*."
50+
51+
**Output:** false
52+
53+
**Constraints:**
54+
55+
* `1 <= s.length <= 20`
56+
* `1 <= p.length <= 30`
57+
* `s` contains only lowercase English letters.
58+
* `p` contains only lowercase English letters, `'.'`, and `'*'`.
59+
* It is guaranteed for each appearance of the character `'*'`, there will be a previous valid character to match.
60+
61+
## Solution
62+
63+
```typescript
64+
function isMatch(s: string, p: string): boolean { // NOSONAR
65+
const result = new Array(s.length + 1)
66+
for (let i = 0; i < result.length; i++) {
67+
result[i] = new Array(p.length + 1).fill(false)
68+
}
69+
result[0][0] = true
70+
for (let j = 1; j < result[0].length; j++) {
71+
const pChar = p[j - 1]
72+
if (pChar === '*') {
73+
result[0][j] = result[0][j - 2]
74+
}
75+
}
76+
for (let i = 1; i < result.length; i++) {
77+
for (let j = 1; j < result[0].length; j++) {
78+
const sChar = s[i - 1]
79+
const pChar = p[j - 1]
80+
if (sChar === pChar || pChar === '.') {
81+
result[i][j] = result[i - 1][j - 1]
82+
} else if (pChar === '*') {
83+
const prevCharMatch = sChar === p[j - 2] || p[j - 2] === '.' ? result[i - 1][j] : false
84+
result[i][j] = result[i][j - 2] || prevCharMatch
85+
}
86+
}
87+
}
88+
return result[result.length - 1][result[0].length - 1]
89+
}
90+
91+
export { isMatch }
92+
```

0 commit comments

Comments
 (0)