Skip to content

Commit 3e6bea5

Browse files
authored
Added tasks 199-209
1 parent 315ad0c commit 3e6bea5

File tree

16 files changed

+385
-0
lines changed

16 files changed

+385
-0
lines changed

README.md

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

104104
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
105105
|-|-|-|-|-|-
106+
| 0209 |[Minimum Size Subarray Sum](src/main/ts/g0201_0300/s0209_minimum_size_subarray_sum/solution.ts)| Medium | Array, Binary_Search, Prefix_Sum, Sliding_Window | 2 | 88.11
106107

107108
#### Day 2
108109

@@ -353,6 +354,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
353354

354355
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
355356
|-|-|-|-|-|-
357+
| 0202 |[Happy Number](src/main/ts/g0201_0300/s0202_happy_number/solution.ts)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers | 0 | 100.00
356358

357359
#### Day 5 Function
358360

@@ -650,6 +652,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
650652

651653
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
652654
|-|-|-|-|-|-
655+
| 0205 |[Isomorphic Strings](src/main/ts/g0201_0300/s0205_isomorphic_strings/solution.ts)| Easy | String, Hash_Table | 3 | 96.02
653656

654657
#### Day 3 Linked List
655658

@@ -734,6 +737,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
734737

735738
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
736739
|-|-|-|-|-|-
740+
| 0202 |[Happy Number](src/main/ts/g0201_0300/s0202_happy_number/solution.ts)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers | 0 | 100.00
737741
| 0054 |[Spiral Matrix](src/main/ts/g0001_0100/s0054_spiral_matrix/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Matrix, Simulation | 0 | 100.00
738742

739743
#### Day 2 String
@@ -824,6 +828,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
824828
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
825829
|-|-|-|-|-|-
826830
| 0101 |[Symmetric Tree](src/main/ts/g0101_0200/s0101_symmetric_tree/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
831+
| 0199 |[Binary Tree Right Side View](src/main/ts/g0101_0200/s0199_binary_tree_right_side_view/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
827832

828833
#### Day 16 Design
829834

@@ -1061,6 +1066,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
10611066

10621067
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10631068
|-|-|-|-|-|-
1069+
| 0209 |[Minimum Size Subarray Sum](src/main/ts/g0201_0300/s0209_minimum_size_subarray_sum/solution.ts)| Medium | Array, Binary_Search, Prefix_Sum, Sliding_Window | 2 | 88.11
10641070
| 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
10651071
| 0030 |[Substring with Concatenation of All Words](src/main/ts/g0001_0100/s0030_substring_with_concatenation_of_all_words/solution.ts)| Hard | String, Hash_Table, Sliding_Window | 13 | 97.44
10661072
| 0076 |[Minimum Window Substring](src/main/ts/g0001_0100/s0076_minimum_window_substring/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(s.length())_Space_O(1) | 20 | 90.35
@@ -1078,8 +1084,10 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
10781084

10791085
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10801086
|-|-|-|-|-|-
1087+
| 0205 |[Isomorphic Strings](src/main/ts/g0201_0300/s0205_isomorphic_strings/solution.ts)| Easy | String, Hash_Table | 3 | 96.02
10811088
| 0049 |[Group Anagrams](src/main/ts/g0001_0100/s0049_group_anagrams/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 27 | 78.99
10821089
| 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
1090+
| 0202 |[Happy Number](src/main/ts/g0201_0300/s0202_happy_number/solution.ts)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers | 0 | 100.00
10831091
| 0128 |[Longest Consecutive Sequence](src/main/ts/g0101_0200/s0128_longest_consecutive_sequence/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Union_Find, Big_O_Time_O(N_log_N)_Space_O(1) | 34 | 90.07
10841092

10851093
#### Top Interview 150 Intervals
@@ -1135,6 +1143,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
11351143

11361144
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11371145
|-|-|-|-|-|-
1146+
| 0199 |[Binary Tree Right Side View](src/main/ts/g0101_0200/s0199_binary_tree_right_side_view/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
11381147
| 0102 |[Binary Tree Level Order Traversal](src/main/ts/g0101_0200/s0102_binary_tree_level_order_traversal/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00
11391148
| 0103 |[Binary Tree Zigzag Level Order Traversal](src/main/ts/g0101_0200/s0103_binary_tree_zigzag_level_order_traversal/solution.ts)| Medium | Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
11401149

@@ -1218,6 +1227,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
12181227
| 0191 |[Number of 1 Bits](src/main/ts/g0101_0200/s0191_number_of_1_bits/solution.ts)| Easy | Top_Interview_Questions, Bit_Manipulation | 0 | 100.00
12191228
| 0136 |[Single Number](src/main/ts/g0101_0200/s0136_single_number/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Bit_Manipulation, Big_O_Time_O(N)_Space_O(1) | 1 | 78.27
12201229
| 0137 |[Single Number II](src/main/ts/g0101_0200/s0137_single_number_ii/solution.ts)| Medium | Array, Bit_Manipulation | 0 | 100.00
1230+
| 0201 |[Bitwise AND of Numbers Range](src/main/ts/g0201_0300/s0201_bitwise_and_of_numbers_range/solution.ts)| Medium | Bit_Manipulation | 2 | 99.12
12211231

12221232
#### Top Interview 150 Math
12231233

@@ -1446,6 +1456,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
14461456

14471457
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
14481458
|-|-|-|-|-|-
1459+
| 0199 |[Binary Tree Right Side View](src/main/ts/g0101_0200/s0199_binary_tree_right_side_view/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
14491460

14501461
#### Day 17 Tree
14511462

@@ -1600,6 +1611,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
16001611
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
16011612
|-|-|-|-|-|-
16021613
| 0438 |[Find All Anagrams in a String](src/main/ts/g0401_0500/s0438_find_all_anagrams_in_a_string/solution.ts)| Medium | Top_100_Liked_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n+m)_Space_O(1) | 8 | 97.80
1614+
| 0209 |[Minimum Size Subarray Sum](src/main/ts/g0201_0300/s0209_minimum_size_subarray_sum/solution.ts)| Medium | Array, Binary_Search, Prefix_Sum, Sliding_Window | 2 | 88.11
16031615

16041616
#### Day 6 Breadth First Search Depth First Search
16051617

@@ -1686,6 +1698,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
16861698

16871699
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
16881700
|-|-|-|-|-|-
1701+
| 0201 |[Bitwise AND of Numbers Range](src/main/ts/g0201_0300/s0201_bitwise_and_of_numbers_range/solution.ts)| Medium | Bit_Manipulation | 2 | 99.12
16891702

16901703
#### Day 20 Others
16911704

@@ -1696,6 +1709,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
16961709

16971710
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
16981711
|-|-|-|-|-|-
1712+
| 0202 |[Happy Number](src/main/ts/g0201_0300/s0202_happy_number/solution.ts)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers | 0 | 100.00
16991713
| 0149 |[Max Points on a Line](src/main/ts/g0101_0200/s0149_max_points_on_a_line/solution.ts)| Hard | Top_Interview_Questions, Array, Hash_Table, Math, Geometry | 9 | 97.18
17001714

17011715
## Algorithms
@@ -1729,10 +1743,15 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
17291743
| 0226 |[Invert Binary Tree](src/main/ts/g0201_0300/s0226_invert_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Data_Structure_I_Day_12_Tree, Level_2_Day_6_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Binary_Tree_General, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
17301744
| 0221 |[Maximal Square](src/main/ts/g0201_0300/s0221_maximal_square/solution.ts)| Medium | Array, Dynamic_Programming, Matrix, Dynamic_Programming_I_Day_16, Top_Interview_150_Multidimensional_DP, Big_O_Time_O(m\*n)_Space_O(m\*n) | 18 | 59.02
17311745
| 0215 |[Kth Largest Element in an Array](src/main/ts/g0201_0300/s0215_kth_largest_element_in_an_array/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Quickselect, Data_Structure_II_Day_20_Heap_Priority_Queue, Top_Interview_150_Heap, Big_O_Time_O(n\*log(n))_Space_O(log(n)) | 4 | 99.64
1746+
| 0209 |[Minimum Size Subarray Sum](src/main/ts/g0201_0300/s0209_minimum_size_subarray_sum/solution.ts)| Medium | Array, Binary_Search, Prefix_Sum, Sliding_Window, Algorithm_II_Day_5_Sliding_Window, Binary_Search_II_Day_1, Top_Interview_150_Sliding_Window | 2 | 88.11
17321747
| 0208 |[Implement Trie (Prefix Tree)](src/main/ts/g0201_0300/s0208_implement_trie_prefix_tree/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, Level_2_Day_16_Design, Udemy_Trie_and_Heap, Top_Interview_150_Trie, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 48 | 63.95
17331748
| 0207 |[Course Schedule](src/main/ts/g0201_0300/s0207_course_schedule/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort, Top_Interview_150_Graph_General, Big_O_Time_O(N)_Space_O(N) | 11 | 81.08
17341749
| 0206 |[Reverse Linked List](src/main/ts/g0201_0300/s0206_reverse_linked_list/solution.ts)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Data_Structure_I_Day_8_Linked_List, Algorithm_I_Day_10_Recursion_Backtracking, Level_1_Day_3_Linked_List, Udemy_Linked_List, Big_O_Time_O(N)_Space_O(1) | 0 | 100.00
1750+
| 0205 |[Isomorphic Strings](src/main/ts/g0201_0300/s0205_isomorphic_strings/solution.ts)| Easy | String, Hash_Table, Level_1_Day_2_String, Top_Interview_150_Hashmap | 3 | 96.02
1751+
| 0202 |[Happy Number](src/main/ts/g0201_0300/s0202_happy_number/solution.ts)| Easy | Top_Interview_Questions, Hash_Table, Math, Two_Pointers, Algorithm_II_Day_21_Others, Programming_Skills_I_Day_4_Loop, Level_2_Day_1_Implementation/Simulation, Top_Interview_150_Hashmap | 0 | 100.00
1752+
| 0201 |[Bitwise AND of Numbers Range](src/main/ts/g0201_0300/s0201_bitwise_and_of_numbers_range/solution.ts)| Medium | Bit_Manipulation, Algorithm_II_Day_19_Bit_Manipulation, Top_Interview_150_Bit_Manipulation | 2 | 99.12
17351753
| 0200 |[Number of Islands](src/main/ts/g0101_0200/s0200_number_of_islands/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Depth_First_Search, Breadth_First_Search, Matrix, Union_Find, Algorithm_II_Day_6_Breadth_First_Search_Depth_First_Search, Graph_Theory_I_Day_1_Matrix_Related_Problems, Level_1_Day_9_Graph/BFS/DFS, Udemy_Graph, Top_Interview_150_Graph_General, Big_O_Time_O(M\*N)_Space_O(M\*N) | 57 | 93.94
1754+
| 0199 |[Binary Tree Right Side View](src/main/ts/g0101_0200/s0199_binary_tree_right_side_view/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Data_Structure_II_Day_16_Tree, Level_2_Day_15_Tree, Top_Interview_150_Binary_Tree_BFS | 0 | 100.00
17361755
| 0198 |[House Robber](src/main/ts/g0101_0200/s0198_house_robber/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Algorithm_I_Day_12_Dynamic_Programming, Dynamic_Programming_I_Day_3, Level_2_Day_12_Dynamic_Programming, Udemy_Dynamic_Programming, Top_Interview_150_1D_DP, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
17371756
| 0191 |[Number of 1 Bits](src/main/ts/g0101_0200/s0191_number_of_1_bits/solution.ts)| Easy | Top_Interview_Questions, Bit_Manipulation, Algorithm_I_Day_13_Bit_Manipulation, Programming_Skills_I_Day_2_Operator, Udemy_Bit_Manipulation, Top_Interview_150_Bit_Manipulation | 0 | 100.00
17381757
| 0190 |[Reverse Bits](src/main/ts/g0101_0200/s0190_reverse_bits/solution.ts)| Easy | Top_Interview_Questions, Bit_Manipulation, Divide_and_Conquer, Algorithm_I_Day_14_Bit_Manipulation, Udemy_Bit_Manipulation, Top_Interview_150_Bit_Manipulation | 34 | 99.74
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
199\. Binary Tree Right Side View
2+
3+
Medium
4+
5+
Given the `root` of a binary tree, imagine yourself standing on the **right side** of it, return _the values of the nodes you can see ordered from top to bottom_.
6+
7+
**Example 1:**
8+
9+
![](https://assets.leetcode.com/uploads/2021/02/14/tree.jpg)
10+
11+
**Input:** root = [1,2,3,null,5,null,4]
12+
13+
**Output:** [1,3,4]
14+
15+
**Example 2:**
16+
17+
**Input:** root = [1,null,3]
18+
19+
**Output:** [1,3]
20+
21+
**Example 3:**
22+
23+
**Input:** root = []
24+
25+
**Output:** []
26+
27+
**Constraints:**
28+
29+
* The number of nodes in the tree is in the range `[0, 100]`.
30+
* `-100 <= Node.val <= 100`
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// #Medium #Top_100_Liked_Questions #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree
2+
// #Data_Structure_II_Day_16_Tree #Level_2_Day_15_Tree #Top_Interview_150_Binary_Tree_BFS
3+
// #2025_04_10_Time_0_ms_(100.00%)_Space_56.98_MB_(73.71%)
4+
5+
import { TreeNode } from '../../com_github_leetcode/treenode'
6+
7+
/**
8+
* Definition for a binary tree node.
9+
* class TreeNode {
10+
* val: number
11+
* left: TreeNode | null
12+
* right: TreeNode | null
13+
* constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
14+
* this.val = (val===undefined ? 0 : val)
15+
* this.left = (left===undefined ? null : left)
16+
* this.right = (right===undefined ? null : right)
17+
* }
18+
* }
19+
*/
20+
function rightSideView(root: TreeNode | null): number[] {
21+
const result: number[] = []
22+
function recurse(node: TreeNode | null, level: number): void {
23+
if (node !== null) {
24+
if (result.length === level) {
25+
result.push(node.val)
26+
}
27+
recurse(node.right, level + 1)
28+
recurse(node.left, level + 1)
29+
}
30+
}
31+
recurse(root, 0)
32+
return result
33+
}
34+
35+
export { rightSideView }
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
201\. Bitwise AND of Numbers Range
2+
3+
Medium
4+
5+
Given two integers `left` and `right` that represent the range `[left, right]`, return _the bitwise AND of all numbers in this range, inclusive_.
6+
7+
**Example 1:**
8+
9+
**Input:** left = 5, right = 7
10+
11+
**Output:** 4
12+
13+
**Example 2:**
14+
15+
**Input:** left = 0, right = 0
16+
17+
**Output:** 0
18+
19+
**Example 3:**
20+
21+
**Input:** left = 1, right = 2147483647
22+
23+
**Output:** 0
24+
25+
**Constraints:**
26+
27+
* <code>0 <= left <= right <= 2<sup>31</sup> - 1</code>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// #Medium #Bit_Manipulation #Algorithm_II_Day_19_Bit_Manipulation
2+
// #Top_Interview_150_Bit_Manipulation #2025_04_10_Time_2_ms_(99.12%)_Space_64.48_MB_(7.02%)
3+
4+
function rangeBitwiseAnd(left: number, right: number): number {
5+
const MASKS: number[] = [
6+
0x00000000, 0x80000000, 0xc0000000, 0xe0000000, 0xf0000000, 0xf8000000, 0xfc000000, 0xfe000000, 0xff000000,
7+
0xff800000, 0xffc00000, 0xffe00000, 0xfff00000, 0xfff80000, 0xfffc0000, 0xfffe0000, 0xffff0000, 0xffff8000,
8+
0xffffc000, 0xffffe000, 0xfffff000, 0xfffff800, 0xfffffc00, 0xfffffe00, 0xffffff00, 0xffffff80, 0xffffffc0,
9+
0xffffffe0, 0xfffffff0, 0xfffffff8, 0xfffffffc, 0xfffffffe,
10+
]
11+
if (left === right) {
12+
return left
13+
}
14+
const leadingZeros = Math.clz32(left ^ right)
15+
return right & MASKS[leadingZeros]
16+
}
17+
18+
export { rangeBitwiseAnd }
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
202\. Happy Number
2+
3+
Easy
4+
5+
Write an algorithm to determine if a number `n` is happy.
6+
7+
A **happy number** is a number defined by the following process:
8+
9+
* Starting with any positive integer, replace the number by the sum of the squares of its digits.
10+
* Repeat the process until the number equals 1 (where it will stay), or it **loops endlessly in a cycle** which does not include 1.
11+
* Those numbers for which this process **ends in 1** are happy.
12+
13+
Return `true` _if_ `n` _is a happy number, and_ `false` _if not_.
14+
15+
**Example 1:**
16+
17+
**Input:** n = 19
18+
19+
**Output:** true
20+
21+
**Explanation:**
22+
23+
1<sup>2</sup> + 9<sup>2</sup> = 82
24+
25+
8<sup>2</sup> + 2<sup>2</sup> = 68
26+
27+
6<sup>2</sup> + 8<sup>2</sup> = 100
28+
29+
1<sup>2</sup> + 0<sup>2</sup> + 0<sup>2</sup> = 1
30+
31+
**Example 2:**
32+
33+
**Input:** n = 2
34+
35+
**Output:** false
36+
37+
**Constraints:**
38+
39+
* <code>1 <= n <= 2<sup>31</sup> - 1</code>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// #Easy #Top_Interview_Questions #Hash_Table #Math #Two_Pointers #Algorithm_II_Day_21_Others
2+
// #Programming_Skills_I_Day_4_Loop #Level_2_Day_1_Implementation/Simulation
3+
// #Top_Interview_150_Hashmap #2025_04_10_Time_0_ms_(100.00%)_Space_55.45_MB_(83.98%)
4+
5+
function isHappy(n: number): boolean {
6+
let a = n
7+
let rem: number
8+
let sum = 0
9+
if (a === 1 || a === 7) {
10+
return true
11+
} else if (a > 1 && a < 10) {
12+
return false
13+
} else {
14+
while (a !== 0) {
15+
rem = a % 10
16+
sum += rem * rem
17+
a = Math.floor(a / 10)
18+
}
19+
return sum === 1 ? true : isHappy(sum)
20+
}
21+
}
22+
23+
export { isHappy }
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
205\. Isomorphic Strings
2+
3+
Easy
4+
5+
Given two strings `s` and `t`, _determine if they are isomorphic_.
6+
7+
Two strings `s` and `t` are isomorphic if the characters in `s` can be replaced to get `t`.
8+
9+
All occurrences of a character must be replaced with another character while preserving the order of characters. No two characters may map to the same character, but a character may map to itself.
10+
11+
**Example 1:**
12+
13+
**Input:** s = "egg", t = "add"
14+
15+
**Output:** true
16+
17+
**Example 2:**
18+
19+
**Input:** s = "foo", t = "bar"
20+
21+
**Output:** false
22+
23+
**Example 3:**
24+
25+
**Input:** s = "paper", t = "title"
26+
27+
**Output:** true
28+
29+
**Constraints:**
30+
31+
* <code>1 <= s.length <= 5 * 10<sup>4</sup></code>
32+
* `t.length == s.length`
33+
* `s` and `t` consist of any valid ascii character.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// #Easy #String #Hash_Table #Level_1_Day_2_String #Top_Interview_150_Hashmap
2+
// #2025_04_10_Time_3_ms_(96.02%)_Space_56.62_MB_(65.86%)
3+
4+
function isIsomorphic(s: string, t: string): boolean {
5+
if (s.length !== t.length) {
6+
return false
7+
}
8+
const mapS = new Map<string, string>()
9+
const mapT = new Map<string, string>()
10+
for (let i = 0; i < s.length; i++) {
11+
if (mapS.has(s[i]) || mapT.has(t[i])) {
12+
if (mapS.get(s[i]) !== t[i] || mapT.get(t[i]) !== s[i]) {
13+
return false
14+
}
15+
} else {
16+
mapS.set(s[i], t[i])
17+
mapT.set(t[i], s[i])
18+
}
19+
}
20+
return true
21+
}
22+
23+
export { isIsomorphic }
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
209\. Minimum Size Subarray Sum
2+
3+
Medium
4+
5+
Given an array of positive integers `nums` and a positive integer `target`, return the minimal length of a **contiguous subarray** <code>[nums<sub>l</sub>, nums<sub>l+1</sub>, ..., nums<sub>r-1</sub>, nums<sub>r</sub>]</code> of which the sum is greater than or equal to `target`. If there is no such subarray, return `0` instead.
6+
7+
**Example 1:**
8+
9+
**Input:** target = 7, nums = [2,3,1,2,4,3]
10+
11+
**Output:** 2
12+
13+
**Explanation:** The subarray [4,3] has the minimal length under the problem constraint.
14+
15+
**Example 2:**
16+
17+
**Input:** target = 4, nums = [1,4,4]
18+
19+
**Output:** 1
20+
21+
**Example 3:**
22+
23+
**Input:** target = 11, nums = [1,1,1,1,1,1,1,1]
24+
25+
**Output:** 0
26+
27+
**Constraints:**
28+
29+
* <code>1 <= target <= 10<sup>9</sup></code>
30+
* <code>1 <= nums.length <= 10<sup>5</sup></code>
31+
* <code>1 <= nums[i] <= 10<sup>5</sup></code>
32+
33+
**Follow up:** If you have figured out the `O(n)` solution, try coding another solution of which the time complexity is `O(n log(n))`.

0 commit comments

Comments
 (0)