Skip to content

Commit fb741da

Browse files
authored
Added tasks 100, 274, 380, 399
1 parent ae738f1 commit fb741da

File tree

16 files changed

+484
-38
lines changed

16 files changed

+484
-38
lines changed

README.md

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

519519
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
520520
|-|-|-|-|-|-
521+
| 0380 |[Insert Delete GetRandom O(1)](src/main/ts/g0301_0400/s0380_insert_delete_getrandom_o1/solution.ts)| Medium | Array, Hash_Table, Math, Design, Randomized | 73 | 82.52
521522

522523
### Graph Theory I
523524

@@ -834,6 +835,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
834835

835836
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
836837
|-|-|-|-|-|-
838+
| 0100 |[Same Tree](src/main/ts/g0001_0100/s0100_same_tree/solution.ts)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
837839
| 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
838840
| 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
839841

@@ -976,6 +978,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
976978
| 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
977979
| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/ts/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/solution.ts)| Easy | Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer | 0 | 100.00
978980
| 0543 |[Diameter of Binary Tree](src/main/ts/g0501_0600/s0543_diameter_of_binary_tree/solution.ts)| Easy | Top_100_Liked_Questions, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(n)_Space_O(n) | 1 | 87.16
981+
| 0100 |[Same Tree](src/main/ts/g0001_0100/s0100_same_tree/solution.ts)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
979982
| 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, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
980983
| 0104 |[Maximum Depth of Binary Tree](src/main/ts/g0101_0200/s0104_maximum_depth_of_binary_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(H) | 0 | 100.00
981984
| 0124 |[Binary Tree Maximum Path Sum](src/main/ts/g0101_0200/s0124_binary_tree_maximum_path_sum/solution.ts)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 2 | 71.11
@@ -1049,6 +1052,8 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
10491052
| 0122 |[Best Time to Buy and Sell Stock II](src/main/ts/g0101_0200/s0122_best_time_to_buy_and_sell_stock_ii/solution.ts)| Medium | Top_Interview_Questions, Array, Dynamic_Programming, Greedy | 0 | 100.00
10501053
| 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
10511054
| 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
1055+
| 0274 |[H-Index](src/main/ts/g0201_0300/s0274_h_index/solution.ts)| Medium | Array, Sorting, Counting_Sort | 0 | 100.00
1056+
| 0380 |[Insert Delete GetRandom O(1)](src/main/ts/g0301_0400/s0380_insert_delete_getrandom_o1/solution.ts)| Medium | Array, Hash_Table, Math, Design, Randomized | 73 | 82.52
10521057
| 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
10531058
| 0134 |[Gas Station](src/main/ts/g0101_0200/s0134_gas_station/solution.ts)| Medium | Top_Interview_Questions, Array, Greedy | 0 | 100.00
10541059
| 0135 |[Candy](src/main/ts/g0101_0200/s0135_candy/solution.ts)| Hard | Array, Greedy | 2 | 96.15
@@ -1145,6 +1150,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
11451150
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11461151
|-|-|-|-|-|-
11471152
| 0104 |[Maximum Depth of Binary Tree](src/main/ts/g0101_0200/s0104_maximum_depth_of_binary_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(H) | 0 | 100.00
1153+
| 0100 |[Same Tree](src/main/ts/g0001_0100/s0100_same_tree/solution.ts)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree | 0 | 100.00
11481154
| 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, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
11491155
| 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
11501156
| 0105 |[Construct Binary Tree from Preorder and Inorder Traversal](src/main/ts/g0101_0200/s0105_construct_binary_tree_from_preorder_and_inorder_traversal/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Tree, Binary_Tree, Divide_and_Conquer, Big_O_Time_O(N)_Space_O(N) | 2 | 93.38
@@ -1180,6 +1186,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
11801186
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11811187
|-|-|-|-|-|-
11821188
| 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, Big_O_Time_O(M\*N)_Space_O(M\*N) | 57 | 93.94
1189+
| 0399 |[Evaluate Division](src/main/ts/g0301_0400/s0399_evaluate_division/solution.ts)| Medium | Array, Depth_First_Search, Breadth_First_Search, Graph, Union_Find, Shortest_Path | 0 | 100.00
11831190
| 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, Big_O_Time_O(N)_Space_O(N) | 11 | 81.08
11841191
| 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 | 2 | 99.76
11851192

@@ -1217,7 +1224,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
12171224
|-|-|-|-|-|-
12181225
| 0108 |[Convert Sorted Array to Binary Search Tree](src/main/ts/g0101_0200/s0108_convert_sorted_array_to_binary_search_tree/solution.ts)| Easy | Top_Interview_Questions, Array, Tree, Binary_Tree, Binary_Search_Tree, Divide_and_Conquer | 0 | 100.00
12191226
| 0148 |[Sort List](src/main/ts/g0101_0200/s0148_sort_list/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Sorting, Two_Pointers, Linked_List, Divide_and_Conquer, Merge_Sort, Big_O_Time_O(log(N))_Space_O(log(N)) | 36 | 44.94
1220-
| 0427 |[Construct Quad Tree](src/main/ts/g0401_0500/s0427_construct_quad_tree/solution.ts)| Medium | Array, Tree, Matrix, Divide_and_Conquer | ew 150 | ew 150 Divide and Conquer
1227+
| 0427 |[Construct Quad Tree](src/main/ts/g0401_0500/s0427_construct_quad_tree/solution.ts)| Medium | Array, Tree, Matrix, Divide_and_Conquer | 51 | 96.23
12211228
| 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, Big_O_Time_O(k\*n\*log(k))_Space_O(log(k)) | 4 | 97.65
12221229

12231230
#### Top Interview 150 Kadane's Algorithm
@@ -1765,11 +1772,13 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
17651772
| 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, Algorithm_II_Day_5_Sliding_Window, Programming_Skills_II_Day_12, Level_1_Day_12_Sliding_Window/Two_Pointer, Big_O_Time_O(n+m)_Space_O(1) | 8 | 97.80
17661773
| 0437 |[Path Sum III](src/main/ts/g0401_0500/s0437_path_sum_iii/solution.ts)| Medium | Depth_First_Search, Tree, Binary_Tree, Level_2_Day_7_Tree, Big_O_Time_O(n)_Space_O(n) | 3 | 86.41
17671774
| 0433 |[Minimum Genetic Mutation](src/main/ts/g0401_0500/s0433_minimum_genetic_mutation/solution.ts)| Medium | String, Hash_Table, Breadth_First_Search, Graph_Theory_I_Day_12_Breadth_First_Search, Top_Interview_150_Graph_BFS | 0 | 100.00
1768-
| 0427 |[Construct Quad Tree](src/main/ts/g0401_0500/s0427_construct_quad_tree/solution.ts)| Medium | Array, Tree, Matrix, Divide_and_Conquer | ew 150 | ew 150 Divide and Conquer
1775+
| 0427 |[Construct Quad Tree](src/main/ts/g0401_0500/s0427_construct_quad_tree/solution.ts)| Medium | Array, Tree, Matrix, Divide_and_Conquer, Top_Interview_150_Divide_and_Conquer | 51 | 96.23
17691776
| 0416 |[Partition Equal Subset Sum](src/main/ts/g0401_0500/s0416_partition_equal_subset_sum/solution.ts)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Level_2_Day_13_Dynamic_Programming, Big_O_Time_O(n\*sums)_Space_O(n\*sums) | 33 | 93.24
1777+
| 0399 |[Evaluate Division](src/main/ts/g0301_0400/s0399_evaluate_division/solution.ts)| Medium | Array, Depth_First_Search, Breadth_First_Search, Graph, Union_Find, Shortest_Path, Top_Interview_150_Graph_General | 0 | 100.00
17701778
| 0394 |[Decode String](src/main/ts/g0301_0400/s0394_decode_string/solution.ts)| Medium | Top_100_Liked_Questions, String, Stack, Recursion, Level_1_Day_14_Stack, Udemy_Strings, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
17711779
| 0392 |[Is Subsequence](src/main/ts/g0301_0400/s0392_is_subsequence/solution.ts)| Easy | String, Dynamic_Programming, Two_Pointers, Dynamic_Programming_I_Day_19, Level_1_Day_2_String, Udemy_Two_Pointers, Top_Interview_150_Two_Pointers | 0 | 100.00
17721780
| 0383 |[Ransom Note](src/main/ts/g0301_0400/s0383_ransom_note/solution.ts)| Easy | String, Hash_Table, Counting, Data_Structure_I_Day_6_String, Top_Interview_150_Hashmap | 4 | 97.40
1781+
| 0380 |[Insert Delete GetRandom O(1)](src/main/ts/g0301_0400/s0380_insert_delete_getrandom_o1/solution.ts)| Medium | Array, Hash_Table, Math, Design, Randomized, Programming_Skills_II_Day_20, Top_Interview_150_Array/String | 73 | 82.52
17731782
| 0373 |[Find K Pairs with Smallest Sums](src/main/ts/g0301_0400/s0373_find_k_pairs_with_smallest_sums/solution.ts)| Medium | Array, Heap_Priority_Queue, Top_Interview_150_Heap | 42 | 85.15
17741783
| 0347 |[Top K Frequent Elements](src/main/ts/g0301_0400/s0347_top_k_frequent_elements/solution.ts)| Medium | Top_100_Liked_Questions, Array, Hash_Table, Sorting, Heap_Priority_Queue, Counting, Divide_and_Conquer, Quickselect, Bucket_Sort, Data_Structure_II_Day_20_Heap_Priority_Queue, Big_O_Time_O(n\*log(n))_Space_O(k) | 7 | 87.13
17751784
| 0338 |[Counting Bits](src/main/ts/g0301_0400/s0338_counting_bits/solution.ts)| Easy | Dynamic_Programming, Bit_Manipulation, Udemy_Bit_Manipulation, Big_O_Time_O(num)_Space_O(num) | 1 | 89.22
@@ -1780,6 +1789,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
17801789
| 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
17811790
| 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
17821791
| 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
1792+
| 0274 |[H-Index](src/main/ts/g0201_0300/s0274_h_index/solution.ts)| Medium | Array, Sorting, Counting_Sort, Top_Interview_150_Array/String | 0 | 100.00
17831793
| 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
17841794
| 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
17851795
| 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
@@ -1853,6 +1863,7 @@ TypeScript-based LeetCode algorithm problem solutions, regularly updated.
18531863
| 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, Data_Structure_II_Day_15_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Binary_Tree_BFS | 0 | 100.00
18541864
| 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, Data_Structure_I_Day_11_Tree, Level_1_Day_6_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Binary_Tree_BFS, Big_O_Time_O(N)_Space_O(N) | 0 | 100.00
18551865
| 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, Data_Structure_I_Day_11_Tree, Level_2_Day_15_Tree, Top_Interview_150_Binary_Tree_General, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
1866+
| 0100 |[Same Tree](src/main/ts/g0001_0100/s0100_same_tree/solution.ts)| Easy | Depth_First_Search, Breadth_First_Search, Tree, Binary_Tree, Level_2_Day_15_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Binary_Tree_General | 0 | 100.00
18561867
| 0098 |[Validate Binary Search Tree](src/main/ts/g0001_0100/s0098_validate_binary_search_tree/solution.ts)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Data_Structure_I_Day_14_Tree, Level_1_Day_8_Binary_Search_Tree, Udemy_Tree_Stack_Queue, Top_Interview_150_Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
18571868
| 0097 |[Interleaving String](src/main/ts/g0001_0100/s0097_interleaving_string/solution.ts)| Medium | String, Dynamic_Programming, Top_Interview_150_Multidimensional_DP | 43 | 97.65
18581869
| 0096 |[Unique Binary Search Trees](src/main/ts/g0001_0100/s0096_unique_binary_search_trees/solution.ts)| Medium | Dynamic_Programming, Math, Tree, Binary_Tree, Binary_Search_Tree, Dynamic_Programming_I_Day_11, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00

src/main/ts/g0001_0100/s0098_validate_binary_search_tree/solution.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@
55

66
import { TreeNode } from '../../com_github_leetcode/treenode'
77

8+
/**
9+
* Definition for a binary tree node.
10+
* class TreeNode {
11+
* val: number
12+
* left: TreeNode | null
13+
* right: TreeNode | null
14+
* constructor(val?: number, left?: TreeNode | null, right?: TreeNode | null) {
15+
* this.val = (val===undefined ? 0 : val)
16+
* this.left = (left===undefined ? null : left)
17+
* this.right = (right===undefined ? null : right)
18+
* }
19+
* }
20+
*/
821
function dfs(node: TreeNode | null, lowerBound: number, upperBound: number): boolean {
922
if (!node) return true
1023
if (node.val <= lowerBound) return false
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
100\. Same Tree
2+
3+
Easy
4+
5+
Given the roots of two binary trees `p` and `q`, write a function to check if they are the same or not.
6+
7+
Two binary trees are considered the same if they are structurally identical, and the nodes have the same value.
8+
9+
**Example 1:**
10+
11+
![](https://assets.leetcode.com/uploads/2020/12/20/ex1.jpg)
12+
13+
**Input:** p = [1,2,3], q = [1,2,3]
14+
15+
**Output:** true
16+
17+
**Example 2:**
18+
19+
![](https://assets.leetcode.com/uploads/2020/12/20/ex2.jpg)
20+
21+
**Input:** p = [1,2], q = [1,null,2]
22+
23+
**Output:** false
24+
25+
**Example 3:**
26+
27+
![](https://assets.leetcode.com/uploads/2020/12/20/ex3.jpg)
28+
29+
**Input:** p = [1,2,1], q = [1,1,2]
30+
31+
**Output:** false
32+
33+
**Constraints:**
34+
35+
* The number of nodes in both trees is in the range `[0, 100]`.
36+
* <code>-10<sup>4</sup> <= Node.val <= 10<sup>4</sup></code>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// #Easy #Depth_First_Search #Breadth_First_Search #Tree #Binary_Tree #Level_2_Day_15_Tree
2+
// #Udemy_Tree_Stack_Queue #Top_Interview_150_Binary_Tree_General
3+
// #2025_04_16_Time_0_ms_(100.00%)_Space_55.66_MB_(67.00%)
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 isSameTree(p: TreeNode | null, q: TreeNode | null): boolean {
21+
if (p === null || q === null) {
22+
return p === null && q === null
23+
}
24+
const b1 = isSameTree(p.left, q.left)
25+
const b2 = isSameTree(p.right, q.right)
26+
return p.val === q.val && b1 && b2
27+
}
28+
29+
export { isSameTree }
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
274\. H-Index
2+
3+
Medium
4+
5+
Given an array of integers `citations` where `citations[i]` is the number of citations a researcher received for their <code>i<sup>th</sup></code> paper, return compute the researcher's `h`**\-index**.
6+
7+
According to the [definition of h-index on Wikipedia](https://en.wikipedia.org/wiki/H-index): A scientist has an index `h` if `h` of their `n` papers have at least `h` citations each, and the other `n − h` papers have no more than `h` citations each.
8+
9+
If there are several possible values for `h`, the maximum one is taken as the `h`**\-index**.
10+
11+
**Example 1:**
12+
13+
**Input:** citations = [3,0,6,1,5]
14+
15+
**Output:** 3
16+
17+
**Explanation:**
18+
19+
[3,0,6,1,5] means the researcher has 5 papers in total and each of them had received 3, 0, 6, 1, 5 citations respectively.
20+
Since the researcher has 3 papers with at least 3 citations each and the remaining two with no more than 3 citations each, their h-index is 3.
21+
22+
**Example 2:**
23+
24+
**Input:** citations = [1,3,1]
25+
26+
**Output:** 1
27+
28+
**Constraints:**
29+
30+
* `n == citations.length`
31+
* `1 <= n <= 5000`
32+
* `0 <= citations[i] <= 1000`
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// #Medium #Array #Sorting #Counting_Sort #Top_Interview_150_Array/String
2+
// #2025_04_16_Time_0_ms_(100.00%)_Space_54.06_MB_(91.25%)
3+
4+
function hIndex(citations: number[]): number {
5+
const len = citations.length
6+
const freqArray = new Array(len + 1).fill(0)
7+
for (const citation of citations) {
8+
freqArray[Math.min(citation, len)]++
9+
}
10+
let totalSoFar = 0
11+
for (let k = len; k >= 0; k--) {
12+
totalSoFar += freqArray[k]
13+
if (totalSoFar >= k) {
14+
return k
15+
}
16+
}
17+
return -1
18+
}
19+
20+
export { hIndex }

0 commit comments

Comments
 (0)