Skip to content

Commit 5a466ca

Browse files
authored
Added tasks 224-290
1 parent 1717ca1 commit 5a466ca

File tree

16 files changed

+450
-2
lines changed

16 files changed

+450
-2
lines changed

README.md

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

394394
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
395395
|-|-|-|-|-|-
396+
| 0242 |[Valid Anagram](src/main/ts/g0201_0300/s0242_valid_anagram/solution.ts)| Easy | String, Hash_Table, Sorting | 4 | 97.99
396397

397398
#### Day 12 Class and Object
398399

@@ -884,6 +885,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
884885
| 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
885886
| 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
886887
| 0394 |[Decode String](src/main/ts/g0301_0400/s0394_decode_string/solution.ts)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
888+
| 0242 |[Valid Anagram](src/main/ts/g0201_0300/s0242_valid_anagram/solution.ts)| Easy | String, Hash_Table, Sorting | 4 | 97.99
887889
| 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
888890
| 0151 |[Reverse Words in a String](src/main/ts/g0101_0200/s0151_reverse_words_in_a_string/solution.ts)| Medium | String, Two_Pointers | 0 | 100.00
889891

@@ -1081,12 +1083,15 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
10811083
| 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
10821084
| 0048 |[Rotate Image](src/main/ts/g0001_0100/s0048_rotate_image/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 0 | 100.00
10831085
| 0073 |[Set Matrix Zeroes](src/main/ts/g0001_0100/s0073_set_matrix_zeroes/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Matrix, Big_O_Time_O(m\*n)_Space_O(1) | 4 | 50.63
1086+
| 0289 |[Game of Life](src/main/ts/g0201_0300/s0289_game_of_life/solution.ts)| Medium | Array, Matrix, Simulation | 0 | 100.00
10841087

10851088
#### Top Interview 150 Hashmap
10861089

10871090
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10881091
|-|-|-|-|-|-
10891092
| 0205 |[Isomorphic Strings](src/main/ts/g0201_0300/s0205_isomorphic_strings/solution.ts)| Easy | String, Hash_Table | 3 | 96.02
1093+
| 0290 |[Word Pattern](src/main/ts/g0201_0300/s0290_word_pattern/solution.ts)| Easy | String, Hash_Table | 0 | 100.00
1094+
| 0242 |[Valid Anagram](src/main/ts/g0201_0300/s0242_valid_anagram/solution.ts)| Easy | String, Hash_Table, Sorting | 4 | 97.99
10901095
| 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
10911096
| 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
10921097
| 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
@@ -1097,6 +1102,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
10971102

10981103
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
10991104
|-|-|-|-|-|-
1105+
| 0228 |[Summary Ranges](src/main/ts/g0201_0300/s0228_summary_ranges/solution.ts)| Easy | Array | 0 | 100.00
11001106
| 0056 |[Merge Intervals](src/main/ts/g0001_0100/s0056_merge_intervals/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 7 | 87.99
11011107
| 0057 |[Insert Interval](src/main/ts/g0001_0100/s0057_insert_interval/solution.ts)| Medium | Array | 0 | 100.00
11021108

@@ -1108,6 +1114,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
11081114
| 0071 |[Simplify Path](src/main/ts/g0001_0100/s0071_simplify_path/solution.ts)| Medium | String, Stack | 0 | 100.00
11091115
| 0155 |[Min Stack](src/main/ts/g0101_0200/s0155_min_stack/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 5 | 99.10
11101116
| 0150 |[Evaluate Reverse Polish Notation](src/main/ts/g0101_0200/s0150_evaluate_reverse_polish_notation/solution.ts)| Medium | Top_Interview_Questions, Array, Math, Stack | 1 | 97.48
1117+
| 0224 |[Basic Calculator](src/main/ts/g0201_0300/s0224_basic_calculator/solution.ts)| Hard | String, Math, Stack, Recursion | 6 | 96.62
11111118

11121119
#### Top Interview 150 Linked List
11131120

@@ -1178,7 +1185,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
11781185
|-|-|-|-|-|-
11791186
| 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, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 48 | 63.95
11801187
| 0211 |[Design Add and Search Words Data Structure](src/main/ts/g0201_0300/s0211_design_add_and_search_words_data_structure/solution.ts)| Medium | String, Depth_First_Search, Design, Trie | 450 | 92.88
1181-
| 0212 |[Word Search II](src/main/ts/g0201_0300/s0212_word_search_ii/solution.ts)| Hard | Top_Interview_Questions, Array, String, Matrix, Backtracking, Trie | ew 150 | ew 150 Trie
1188+
| 0212 |[Word Search II](src/main/ts/g0201_0300/s0212_word_search_ii/solution.ts)| Hard | Top_Interview_Questions, Array, String, Matrix, Backtracking, Trie | 62 | 99.46
11821189

11831190
#### Top Interview 150 Backtracking
11841191

@@ -1308,6 +1315,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
13081315

13091316
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
13101317
|-|-|-|-|-|-
1318+
| 0242 |[Valid Anagram](src/main/ts/g0201_0300/s0242_valid_anagram/solution.ts)| Easy | String, Hash_Table, Sorting | 4 | 97.99
13111319

13121320
#### Day 7 Linked List
13131321

@@ -1405,6 +1413,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
14051413

14061414
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
14071415
|-|-|-|-|-|-
1416+
| 0290 |[Word Pattern](src/main/ts/g0201_0300/s0290_word_pattern/solution.ts)| Easy | String, Hash_Table | 0 | 100.00
14081417
| 0763 |[Partition Labels](src/main/ts/g0701_0800/s0763_partition_labels/solution.ts)| Medium | String, Hash_Table, Greedy, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 4 | 86.89
14091418

14101419
#### Day 8 String
@@ -1739,20 +1748,25 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
17391748
| 0322 |[Coin Change](src/main/ts/g0301_0400/s0322_coin_change/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Breadth_First_Search, Algorithm_II_Day_18_Dynamic_Programming, Dynamic_Programming_I_Day_20, Level_2_Day_12_Dynamic_Programming, Top_Interview_150_1D_DP, Big_O_Time_O(m\*n)_Space_O(amount) | 27 | 89.42
17401749
| 0300 |[Longest Increasing Subsequence](src/main/ts/g0201_0300/s0300_longest_increasing_subsequence/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Binary_Search, Algorithm_II_Day_16_Dynamic_Programming, Binary_Search_II_Day_3, Dynamic_Programming_I_Day_18, Udemy_Dynamic_Programming, Top_Interview_150_1D_DP, Big_O_Time_O(n\*log_n)_Space_O(n) | 6 | 84.68
17411750
| 0295 |[Find Median from Data Stream](src/main/ts/g0201_0300/s0295_find_median_from_data_stream/solution.ts)| Hard | Top_100_Liked_Questions, Sorting, Two_Pointers, Design, Heap_Priority_Queue, Data_Stream, Top_Interview_150_Heap, Big_O_Time_O(n\*log_n)_Space_O(n) | 106 | 92.31
1751+
| 0290 |[Word Pattern](src/main/ts/g0201_0300/s0290_word_pattern/solution.ts)| Easy | String, Hash_Table, Data_Structure_II_Day_7_String, Top_Interview_150_Hashmap | 0 | 100.00
1752+
| 0289 |[Game of Life](src/main/ts/g0201_0300/s0289_game_of_life/solution.ts)| Medium | Array, Matrix, Simulation, Top_Interview_150_Matrix | 0 | 100.00
17421753
| 0287 |[Find the Duplicate Number](src/main/ts/g0201_0300/s0287_find_the_duplicate_number/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Two_Pointers, Bit_Manipulation, Binary_Search_II_Day_5, Big_O_Time_O(n)_Space_O(n) | 5 | 88.65
17431754
| 0283 |[Move Zeroes](src/main/ts/g0201_0300/s0283_move_zeroes/solution.ts)| Easy | Top_100_Liked_Questions, Array, Two_Pointers, Algorithm_I_Day_3_Two_Pointers, Programming_Skills_I_Day_6_Array, Udemy_Arrays, Big_O_Time_O(n)_Space_O(1) | 1 | 82.86
1755+
| 0242 |[Valid Anagram](src/main/ts/g0201_0300/s0242_valid_anagram/solution.ts)| Easy | String, Hash_Table, Sorting, Data_Structure_I_Day_6_String, Programming_Skills_I_Day_11_Containers_and_Libraries, Udemy_Strings, Top_Interview_150_Hashmap | 4 | 97.99
17441756
| 0240 |[Search a 2D Matrix II](src/main/ts/g0201_0300/s0240_search_a_2d_matrix_ii/solution.ts)| Medium | Top_100_Liked_Questions, Array, Binary_Search, Matrix, Divide_and_Conquer, Data_Structure_II_Day_4_Array, Binary_Search_II_Day_8, Big_O_Time_O(n+m)_Space_O(1) | 42 | 94.61
17451757
| 0239 |[Sliding Window Maximum](src/main/ts/g0201_0300/s0239_sliding_window_maximum/solution.ts)| Hard | Top_100_Liked_Questions, Array, Heap_Priority_Queue, Sliding_Window, Queue, Monotonic_Queue, Udemy_Arrays, Big_O_Time_O(n\*k)_Space_O(n+k) | 26 | 99.07
17461758
| 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, Data_Structure_II_Day_5_Array, Udemy_Arrays, Top_Interview_150_Array/String, Big_O_Time_O(n^2)_Space_O(n) | 3 | 92.81
17471759
| 0236 |[Lowest Common Ancestor of a Binary Tree](src/main/ts/g0201_0300/s0236_lowest_common_ancestor_of_a_binary_tree/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Data_Structure_II_Day_18_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Binary_Tree_General, Big_O_Time_O(n)_Space_O(n) | 61 | 75.97
17481760
| 0234 |[Palindrome Linked List](src/main/ts/g0201_0300/s0234_palindrome_linked_list/solution.ts)| Easy | Top_100_Liked_Questions, Two_Pointers, Stack, Linked_List, Recursion, Level_2_Day_3_Linked_List, Udemy_Linked_List, Big_O_Time_O(n)_Space_O(1) | 3 | 92.85
17491761
| 0230 |[Kth Smallest Element in a BST](src/main/ts/g0201_0300/s0230_kth_smallest_element_in_a_bst/solution.ts)| Medium | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Data_Structure_II_Day_17_Tree, Level_2_Day_9_Binary_Search_Tree, Top_Interview_150_Binary_Search_Tree, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
1762+
| 0228 |[Summary Ranges](src/main/ts/g0201_0300/s0228_summary_ranges/solution.ts)| Easy | Array, Top_Interview_150_Intervals | 0 | 100.00
17501763
| 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
1764+
| 0224 |[Basic Calculator](src/main/ts/g0201_0300/s0224_basic_calculator/solution.ts)| Hard | String, Math, Stack, Recursion, Top_Interview_150_Stack | 6 | 96.62
17511765
| 0222 |[Count Complete Tree Nodes](src/main/ts/g0201_0300/s0222_count_complete_tree_nodes/solution.ts)| Easy | Depth_First_Search, Tree, Binary_Search, Binary_Tree, Binary_Search_II_Day_10, Top_Interview_150_Binary_Tree_General | 0 | 100.00
17521766
| 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
17531767
| 0219 |[Contains Duplicate II](src/main/ts/g0201_0300/s0219_contains_duplicate_ii/solution.ts)| Easy | Array, Hash_Table, Sliding_Window, Top_Interview_150_Hashmap | 17 | 79.29
17541768
| 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
1755-
| 0212 |[Word Search II](src/main/ts/g0201_0300/s0212_word_search_ii/solution.ts)| Hard | Top_Interview_Questions, Array, String, Matrix, Backtracking, Trie | ew 150 | ew 150 Trie
1769+
| 0212 |[Word Search II](src/main/ts/g0201_0300/s0212_word_search_ii/solution.ts)| Hard | Top_Interview_Questions, Array, String, Matrix, Backtracking, Trie, Top_Interview_150_Trie | 62 | 99.46
17561770
| 0211 |[Design Add and Search Words Data Structure](src/main/ts/g0201_0300/s0211_design_add_and_search_words_data_structure/solution.ts)| Medium | String, Depth_First_Search, Design, Trie, Top_Interview_150_Trie | 450 | 92.88
17571771
| 0210 |[Course Schedule II](src/main/ts/g0201_0300/s0210_course_schedule_ii/solution.ts)| Medium | Top_Interview_Questions, Depth_First_Search, Breadth_First_Search, Graph, Topological_Sort, Level_2_Day_11_Graph/BFS/DFS, Top_Interview_150_Graph_General | 2 | 99.76
17581772
| 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
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
224\. Basic Calculator
2+
3+
Hard
4+
5+
Given a string `s` representing a valid expression, implement a basic calculator to evaluate it, and return _the result of the evaluation_.
6+
7+
**Note:** You are **not** allowed to use any built-in function which evaluates strings as mathematical expressions, such as `eval()`.
8+
9+
**Example 1:**
10+
11+
**Input:** s = "1 + 1"
12+
13+
**Output:** 2
14+
15+
**Example 2:**
16+
17+
**Input:** s = " 2-1 + 2 "
18+
19+
**Output:** 3
20+
21+
**Example 3:**
22+
23+
**Input:** s = "(1+(4+5+2)-3)+(6+8)"
24+
25+
**Output:** 23
26+
27+
**Constraints:**
28+
29+
* <code>1 <= s.length <= 3 * 10<sup>5</sup></code>
30+
* `s` consists of digits, `'+'`, `'-'`, `'('`, `')'`, and `' '`.
31+
* `s` represents a valid expression.
32+
* `'+'` is **not** used as a unary operation (i.e., `"+1"` and `"+(2 + 3)"` is invalid).
33+
* `'-'` could be used as a unary operation (i.e., `"-1"` and `"-(2 + 3)"` is valid).
34+
* There will be no two consecutive operators in the input.
35+
* Every number and running calculation will fit in a signed 32-bit integer.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// #Hard #String #Math #Stack #Recursion #Top_Interview_150_Stack
2+
// #2025_04_12_Time_6_ms_(96.62%)_Space_57.57_MB_(89.85%)
3+
4+
function calculate(s: string): number {
5+
let i = 0
6+
7+
function helper(ca: string[]): number {
8+
let num = 0
9+
let prenum = 0
10+
let isPlus = true
11+
while (i < ca.length) {
12+
const c = ca[i]
13+
if (c !== ' ') {
14+
if (c >= '0' && c <= '9') {
15+
num = num * 10 + parseInt(c)
16+
} else if (c === '+') {
17+
prenum += num * (isPlus ? 1 : -1)
18+
isPlus = true
19+
num = 0
20+
} else if (c === '-') {
21+
prenum += num * (isPlus ? 1 : -1)
22+
isPlus = false
23+
num = 0
24+
} else if (c === '(') {
25+
i++
26+
num = helper(ca)
27+
} else if (c === ')') {
28+
prenum += num * (isPlus ? 1 : -1)
29+
return prenum
30+
}
31+
}
32+
i++
33+
}
34+
return prenum + num * (isPlus ? 1 : -1)
35+
}
36+
return helper(s.split(''))
37+
}
38+
39+
export { calculate }
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
228\. Summary Ranges
2+
3+
Easy
4+
5+
You are given a **sorted unique** integer array `nums`.
6+
7+
Return _the **smallest sorted** list of ranges that **cover all the numbers in the array exactly**_. That is, each element of `nums` is covered by exactly one of the ranges, and there is no integer `x` such that `x` is in one of the ranges but not in `nums`.
8+
9+
Each range `[a,b]` in the list should be output as:
10+
11+
* `"a->b"` if `a != b`
12+
* `"a"` if `a == b`
13+
14+
**Example 1:**
15+
16+
**Input:** nums = [0,1,2,4,5,7]
17+
18+
**Output:** ["0->2","4->5","7"]
19+
20+
**Explanation:** The ranges are: [0,2] --> "0->2" [4,5] --> "4->5" [7,7] --> "7"
21+
22+
**Example 2:**
23+
24+
**Input:** nums = [0,2,3,4,6,8,9]
25+
26+
**Output:** ["0","2->4","6","8->9"]
27+
28+
**Explanation:** The ranges are: [0,0] --> "0" [2,4] --> "2->4" [6,6] --> "6" [8,9] --> "8->9"
29+
30+
**Example 3:**
31+
32+
**Input:** nums = []
33+
34+
**Output:** []
35+
36+
**Example 4:**
37+
38+
**Input:** nums = [-1]
39+
40+
**Output:** ["-1"]
41+
42+
**Example 5:**
43+
44+
**Input:** nums = [0]
45+
46+
**Output:** ["0"]
47+
48+
**Constraints:**
49+
50+
* `0 <= nums.length <= 20`
51+
* <code>-2<sup>31</sup> <= nums[i] <= 2<sup>31</sup> - 1</code>
52+
* All the values of `nums` are **unique**.
53+
* `nums` is sorted in ascending order.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// #Easy #Array #Top_Interview_150_Intervals #2025_04_12_Time_0_ms_(100.00%)_Space_55.25_MB_(57.62%)
2+
3+
function summaryRanges(nums: number[]): string[] {
4+
const ranges: string[] = []
5+
const n = nums.length
6+
if (n === 0) {
7+
return ranges
8+
}
9+
let a = nums[0]
10+
let b = a
11+
let strB = ''
12+
for (let i = 1; i < n; i++) {
13+
if (nums[i] !== b + 1) {
14+
strB = a.toString()
15+
if (a !== b) {
16+
strB += '->' + b.toString()
17+
}
18+
ranges.push(strB)
19+
a = nums[i]
20+
b = a
21+
strB = ''
22+
} else {
23+
b++
24+
}
25+
}
26+
strB = a.toString()
27+
if (a !== b) {
28+
strB += '->' + b.toString()
29+
}
30+
ranges.push(strB)
31+
return ranges
32+
}
33+
34+
export { summaryRanges }
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
242\. Valid Anagram
2+
3+
Easy
4+
5+
Given two strings `s` and `t`, return `true` _if_ `t` _is an anagram of_ `s`_, and_ `false` _otherwise_.
6+
7+
**Example 1:**
8+
9+
**Input:** s = "anagram", t = "nagaram"
10+
11+
**Output:** true
12+
13+
**Example 2:**
14+
15+
**Input:** s = "rat", t = "car"
16+
17+
**Output:** false
18+
19+
**Constraints:**
20+
21+
* <code>1 <= s.length, t.length <= 5 * 10<sup>4</sup></code>
22+
* `s` and `t` consist of lowercase English letters.
23+
24+
**Follow up:** What if the inputs contain Unicode characters? How would you adapt your solution to such a case?
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// #Easy #String #Hash_Table #Sorting #Data_Structure_I_Day_6_String
2+
// #Programming_Skills_I_Day_11_Containers_and_Libraries #Udemy_Strings #Top_Interview_150_Hashmap
3+
// #2025_04_12_Time_4_ms_(97.99%)_Space_57.08_MB_(80.13%)
4+
5+
function isAnagram(s: string, t: string): boolean {
6+
if (s.length !== t.length) {
7+
return false
8+
}
9+
let counts = new Array(26).fill(0)
10+
for (let i = 0; i < s.length; ++i) {
11+
counts[s.charCodeAt(i) - 'a'.charCodeAt(0)]++
12+
counts[t.charCodeAt(i) - 'a'.charCodeAt(0)]--
13+
}
14+
return counts.every((c) => c === 0)
15+
}
16+
17+
export { isAnagram }

0 commit comments

Comments
 (0)