Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8d2bdfd

Browse files
authored
Added tasks 207-226
1 parent6138ba8 commit8d2bdfd

File tree

21 files changed

+503
-43
lines changed

21 files changed

+503
-43
lines changed

‎README.md‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,7 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
493493
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
494494
|-|-|-|-|-|-
495495
| 0064 |[Minimum Path Sum](src/main/js/g0001_0100/s0064_minimum_path_sum/solution.js)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 3 | 83.07
496+
| 0221 |[Maximal Square](src/main/js/g0201_0300/s0221_maximal_square/solution.js)| Medium | Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 12 | 87.32
496497

497498
####Day 17
498499

@@ -936,6 +937,7 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
936937

937938
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
938939
|-|-|-|-|-|-
940+
| 0226 |[Invert Binary Tree](src/main/js/g0201_0300/s0226_invert_binary_tree/solution.js)| 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
939941

940942
####Day 7 Tree
941943

@@ -994,6 +996,7 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
994996
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
995997
|-|-|-|-|-|-
996998
| 0155 |[Min Stack](src/main/js/g0101_0200/s0155_min_stack/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Stack, Design, Big_O_Time_O(1)_Space_O(N) | 6 | 99.32
999+
| 0208 |[Implement Trie (Prefix Tree)](src/main/js/g0201_0300/s0208_implement_trie_prefix_tree/solution.js)| 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) | 39 | 93.97
9971000

9981001
####Day 17 Interval
9991002

@@ -1104,6 +1107,7 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
11041107
|-|-|-|-|-|-
11051108
| 0094 |[Binary Tree Inorder Traversal](src/main/js/g0001_0100/s0094_binary_tree_inorder_traversal/solution.js)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Stack, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
11061109
| 0102 |[Binary Tree Level Order Traversal](src/main/js/g0101_0200/s0102_binary_tree_level_order_traversal/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Breadth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 1 | 87.97
1110+
| 0226 |[Invert Binary Tree](src/main/js/g0201_0300/s0226_invert_binary_tree/solution.js)| 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
11071111
| 0104 |[Maximum Depth of Binary Tree](src/main/js/g0101_0200/s0104_maximum_depth_of_binary_tree/solution.js)| 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
11081112
| 0124 |[Binary Tree Maximum Path Sum](src/main/js/g0101_0200/s0124_binary_tree_maximum_path_sum/solution.js)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Depth_First_Search, Tree, Binary_Tree, Big_O_Time_O(N)_Space_O(N) | 1 | 98.34
11091113
| 0098 |[Validate Binary Search Tree](src/main/js/g0001_0100/s0098_validate_binary_search_tree/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Depth_First_Search, Tree, Binary_Tree, Binary_Search_Tree, Big_O_Time_O(N)_Space_O(log(N)) | 0 | 100.00
@@ -1112,6 +1116,7 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
11121116

11131117
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
11141118
|-|-|-|-|-|-
1119+
| 0208 |[Implement Trie (Prefix Tree)](src/main/js/g0201_0300/s0208_implement_trie_prefix_tree/solution.js)| 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) | 39 | 93.97
11151120

11161121
####Udemy Graph
11171122

@@ -1225,6 +1230,7 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
12251230

12261231
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
12271232
|-|-|-|-|-|-
1233+
| 0226 |[Invert Binary Tree](src/main/js/g0201_0300/s0226_invert_binary_tree/solution.js)| 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
12281234

12291235
####Day 13 Tree
12301236

@@ -1353,6 +1359,7 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
13531359

13541360
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
13551361
|-|-|-|-|-|-
1362+
| 0215 |[Kth Largest Element in an Array](src/main/js/g0201_0300/s0215_kth_largest_element_in_an_array/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Heap_Priority_Queue, Divide_and_Conquer, Quickselect, Big_O_Time_O(n\*log(n))_Space_O(log(n)) | 9 | 97.67
13561363

13571364
####Day 21 Heap Priority Queue
13581365

@@ -1363,6 +1370,11 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
13631370

13641371
| # | Title | Difficulty | Tag | Time, ms | Time, %
13651372
|------|----------------|-------------|-------------|----------|---------
1373+
| 0226 |[Invert Binary Tree](src/main/js/g0201_0300/s0226_invert_binary_tree/solution.js)| 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, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00
1374+
| 0221 |[Maximal Square](src/main/js/g0201_0300/s0221_maximal_square/solution.js)| Medium | Array, Dynamic_Programming, Matrix, Dynamic_Programming_I_Day_16, Big_O_Time_O(m\*n)_Space_O(m\*n) | 12 | 87.32
1375+
| 0215 |[Kth Largest Element in an Array](src/main/js/g0201_0300/s0215_kth_largest_element_in_an_array/solution.js)| 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, Big_O_Time_O(n\*log(n))_Space_O(log(n)) | 9 | 97.67
1376+
| 0208 |[Implement Trie (Prefix Tree)](src/main/js/g0201_0300/s0208_implement_trie_prefix_tree/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Design, Trie, Level_2_Day_16_Design, Udemy_Trie_and_Heap, Big_O_Time_O(word.length())_or_O(prefix.length())_Space_O(N) | 39 | 93.97
1377+
| 0207 |[Course Schedule](src/main/js/g0201_0300/s0207_course_schedule/solution.js)| 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) | 6 | 95.35
13661378
| 0206 |[Reverse Linked List](src/main/js/g0201_0300/s0206_reverse_linked_list/solution.js)| 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
13671379
| 0200 |[Number of Islands](src/main/js/g0101_0200/s0200_number_of_islands/solution.js)| 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, Big_O_Time_O(M\*N)_Space_O(M\*N) | 62 | 90.80
13681380
| 0198 |[House Robber](src/main/js/g0101_0200/s0198_house_robber/solution.js)| 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, Big_O_Time_O(n)_Space_O(n) | 0 | 100.00

‎src/main/js/g0101_0200/s0169_majority_element/solution.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
*@return {number}
88
*/
99
varmajorityElement=function(arr){
10-
letcount=1;
11-
letmajority=arr[0];
10+
letcount=1
11+
letmajority=arr[0]
1212

1313
// For Potential Majority Element
1414
for(leti=1;i<arr.length;i++){
@@ -22,17 +22,17 @@ var majorityElement = function(arr) {
2222
}
2323

2424
// For Confirmation
25-
count=0;
25+
count=0
2626
for(constnumofarr){
2727
if(num===majority){
28-
count++;
28+
count++
2929
}
3030
}
3131

3232
if(count>=Math.floor(arr.length/2)+1){
33-
returnmajority;
33+
returnmajority
3434
}else{
35-
return-1;
35+
return-1
3636
}
3737
};
3838

‎src/main/js/g0101_0200/s0189_rotate_array/solution.js‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@
99
*/
1010
varreverse=function(nums,l,r){
1111
while(l<=r){
12-
lettemp=nums[l];
13-
nums[l]=nums[r];
14-
nums[r]=temp;
15-
l++;
16-
r--;
12+
lettemp=nums[l]
13+
nums[l]=nums[r]
14+
nums[r]=temp
15+
l++
16+
r--
1717
}
1818
};
1919

2020
constrotate=function(nums,k){
21-
constn=nums.length;
22-
constt=n-(k%n);
23-
reverse(nums,0,t-1);
24-
reverse(nums,t,n-1);
25-
reverse(nums,0,n-1);
21+
constn=nums.length
22+
constt=n-(k%n)
23+
reverse(nums,0,t-1)
24+
reverse(nums,t,n-1)
25+
reverse(nums,0,n-1)
2626
};
2727

2828
export{rotate}

‎src/main/js/g0101_0200/s0198_house_robber/solution.js‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,24 @@
99
*/
1010
varrob=function(nums){
1111
if(nums.length===0){
12-
return0;
12+
return0
1313
}
1414
if(nums.length===1){
15-
returnnums[0];
15+
returnnums[0]
1616
}
1717
if(nums.length===2){
18-
returnMath.max(nums[0],nums[1]);
18+
returnMath.max(nums[0],nums[1])
1919
}
2020

21-
constprofit=newArray(nums.length);
22-
profit[0]=nums[0];
23-
profit[1]=Math.max(nums[0],nums[1]);
21+
constprofit=newArray(nums.length)
22+
profit[0]=nums[0]
23+
profit[1]=Math.max(nums[0],nums[1])
2424

2525
for(leti=2;i<nums.length;i++){
26-
profit[i]=Math.max(profit[i-1],nums[i]+profit[i-2]);
26+
profit[i]=Math.max(profit[i-1],nums[i]+profit[i-2])
2727
}
2828

29-
returnprofit[nums.length-1];
29+
returnprofit[nums.length-1]
3030
};
3131

3232
export{rob}

‎src/main/js/g0101_0200/s0200_number_of_islands/solution.js‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@
99
*@return {number}
1010
*/
1111
varnumIslands=function(grid){
12-
letislands=0;
12+
letislands=0
1313

1414
if(grid&&grid.length>0&&grid[0].length>0){
1515
for(leti=0;i<grid.length;i++){
1616
for(letj=0;j<grid[0].length;j++){
1717
if(grid[i][j]==='1'){
18-
dfs(grid,i,j);
19-
islands++;
18+
dfs(grid,i,j)
19+
islands++
2020
}
2121
}
2222
}
2323
}
2424

25-
returnislands;
26-
}
25+
returnislands
26+
};
2727

2828
constdfs=function(grid,x,y){
2929
if(
@@ -33,15 +33,15 @@ const dfs = function(grid, x, y) {
3333
y>=grid[0].length||
3434
grid[x][y]!=='1'
3535
){
36-
return;
36+
return
3737
}
3838

39-
grid[x][y]='x';// Mark as visited
39+
grid[x][y]='x'// Mark as visited
4040

41-
dfs(grid,x+1,y);// Down
42-
dfs(grid,x-1,y);// Up
43-
dfs(grid,x,y+1);// Right
44-
dfs(grid,x,y-1);// Left
45-
}
41+
dfs(grid,x+1,y)// Down
42+
dfs(grid,x-1,y)// Up
43+
dfs(grid,x,y+1)// Right
44+
dfs(grid,x,y-1)// Left
45+
};
4646

4747
export{numIslands}

‎src/main/js/g0201_0300/s0206_reverse_linked_list/solution.js‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@
1515
*@return {ListNode}
1616
*/
1717
varreverseList=function(head){
18-
letprev=null;
19-
letcurr=head;
18+
letprev=null
19+
letcurr=head
2020

2121
while(curr!==null){
22-
letnext=curr.next;
23-
curr.next=prev;
24-
prev=curr;
25-
curr=next;
22+
letnext=curr.next
23+
curr.next=prev
24+
prev=curr
25+
curr=next
2626
}
2727

28-
returnprev;
28+
returnprev
2929
};
3030

3131
export{reverseList}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
207\. Course Schedule
2+
3+
Medium
4+
5+
There are a total of`numCourses` courses you have to take, labeled from`0` to`numCourses - 1`. You are given an array`prerequisites` where <code>prerequisites[i] =[a<sub>i</sub>, b<sub>i</sub>]</code> indicates that you**must** take course <code>b<sub>i</sub></code> first if you want to take course <code>a<sub>i</sub></code>.
6+
7+
* For example, the pair`[0, 1]`, indicates that to take course`0` you have to first take course`1`.
8+
9+
Return`true` if you can finish all courses. Otherwise, return`false`.
10+
11+
**Example 1:**
12+
13+
**Input:** numCourses = 2, prerequisites =[[1,0]]
14+
15+
**Output:** true
16+
17+
**Explanation:** There are a total of 2 courses to take. To take course 1 you should have finished course 0. So it is possible.
18+
19+
**Example 2:**
20+
21+
**Input:** numCourses = 2, prerequisites =[[1,0],[0,1]]
22+
23+
**Output:** false
24+
25+
**Explanation:** There are a total of 2 courses to take. To take course 1 you should have finished course 0, and to take course 0 you should also have finished course 1. So it is impossible.
26+
27+
**Constraints:**
28+
29+
*`1 <= numCourses <= 2000`
30+
*`0 <= prerequisites.length <= 5000`
31+
*`prerequisites[i].length == 2`
32+
* <code>0 <= a<sub>i</sub>, b<sub>i</sub> < numCourses</code>
33+
* All the pairs prerequisites[i] are**unique**.
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Depth_First_Search
2+
// #Breadth_First_Search #Graph #Topological_Sort #Big_O_Time_O(N)_Space_O(N)
3+
// #2024_12_17_Time_6_ms_(95.35%)_Space_57_MB_(39.46%)
4+
5+
/**
6+
*@param {number} numCourses
7+
*@param {number[][]} prerequisites
8+
*@return {boolean}
9+
*/
10+
constWHITE=0;
11+
constGRAY=1;
12+
constBLACK=2;
13+
14+
varcanFinish=function(numCourses,prerequisites){
15+
constadj=Array.from({length:numCourses},()=>[]);
16+
17+
for(const[course,prerequisite]ofprerequisites){
18+
adj[prerequisite].push(course);
19+
}
20+
21+
constcolors=newArray(numCourses).fill(WHITE);
22+
23+
for(leti=0;i<numCourses;i++){
24+
if(colors[i]===WHITE&&adj[i].length>0&&hasCycle(adj,i,colors)){
25+
returnfalse;
26+
}
27+
}
28+
29+
returntrue;
30+
};
31+
32+
varhasCycle=function(adj,node,colors){
33+
colors[node]=GRAY;
34+
35+
for(constneighborofadj[node]){
36+
if(colors[neighbor]===GRAY){
37+
returntrue;
38+
}
39+
if(colors[neighbor]===WHITE&&hasCycle(adj,neighbor,colors)){
40+
returntrue;
41+
}
42+
}
43+
44+
colors[node]=BLACK;
45+
returnfalse;
46+
};
47+
48+
export{canFinish}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
208\. Implement Trie (Prefix Tree)
2+
3+
Medium
4+
5+
A[**trie**](https://en.wikipedia.org/wiki/Trie) (pronounced as "try") or**prefix tree** is a tree data structure used to efficiently store and retrieve keys in a dataset of strings. There are various applications of this data structure, such as autocomplete and spellchecker.
6+
7+
Implement the Trie class:
8+
9+
*`Trie()` Initializes the trie object.
10+
*`void insert(String word)` Inserts the string`word` into the trie.
11+
*`boolean search(String word)` Returns`true` if the string`word` is in the trie (i.e., was inserted before), and`false` otherwise.
12+
*`boolean startsWith(String prefix)` Returns`true` if there is a previously inserted string`word` that has the prefix`prefix`, and`false` otherwise.
13+
14+
**Example 1:**
15+
16+
**Input**["Trie", "insert", "search", "search", "startsWith", "insert", "search"][[],["apple"],["apple"],["app"],["app"],["app"],["app"]]
17+
18+
**Output:**[null, null, true, false, true, null, true]
19+
20+
**Explanation:**
21+
22+
Trie trie = new Trie();
23+
24+
trie.insert("apple");
25+
26+
trie.search("apple"); // return True
27+
28+
trie.search("app"); // return False
29+
30+
trie.startsWith("app"); // return True
31+
32+
trie.insert("app");
33+
34+
trie.search("app"); // return True
35+
36+
**Constraints:**
37+
38+
*`1 <= word.length, prefix.length <= 2000`
39+
*`word` and`prefix` consist only of lowercase English letters.
40+
* At most <code>3 * 10<sup>4</sup></code> calls**in total** will be made to`insert`,`search`, and`startsWith`.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp