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

Commit20a7050

Browse files
authored
Added tasks 39-46
1 parent6abffd5 commit20a7050

File tree

16 files changed

+437
-0
lines changed

16 files changed

+437
-0
lines changed

‎README.md‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
8484

8585
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
8686
|-|-|-|-|-|-
87+
| 0046 |[Permutations](src/main/js/g0001_0100/s0046_permutations/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 0 | 100.00
8788

8889
####Day 12 Dynamic Programming
8990

@@ -155,6 +156,7 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
155156

156157
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
157158
|-|-|-|-|-|-
159+
| 0039 |[Combination Sum](src/main/js/g0001_0100/s0039_combination_sum/solution.js)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 98.51
158160

159161
####Day 11 Recursion Backtracking
160162

@@ -172,6 +174,7 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
172174

173175
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
174176
|-|-|-|-|-|-
177+
| 0045 |[Jump Game II](src/main/js/g0001_0100/s0045_jump_game_ii/solution.js)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
175178

176179
####Day 14 Dynamic Programming
177180

@@ -402,6 +405,7 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
402405

403406
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
404407
|-|-|-|-|-|-
408+
| 0045 |[Jump Game II](src/main/js/g0001_0100/s0045_jump_game_ii/solution.js)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
405409

406410
####Day 5
407411

@@ -427,6 +431,7 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
427431

428432
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
429433
|-|-|-|-|-|-
434+
| 0042 |[Trapping Rain Water](src/main/js/g0001_0100/s0042_trapping_rain_water/solution.js)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
430435

431436
####Day 10
432437

@@ -961,6 +966,8 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
961966

962967
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
963968
|-|-|-|-|-|-
969+
| 0039 |[Combination Sum](src/main/js/g0001_0100/s0039_combination_sum/solution.js)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 98.51
970+
| 0046 |[Permutations](src/main/js/g0001_0100/s0046_permutations/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 0 | 100.00
964971

965972
###Udemy
966973

@@ -990,11 +997,13 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
990997
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
991998
|-|-|-|-|-|-
992999
| 0001 |[Two Sum](src/main/js/g0001_0100/s0001_two_sum/solution.js)| 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.15
1000+
| 0041 |[First Missing Positive](src/main/js/g0001_0100/s0041_first_missing_positive/solution.js)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 1 | 98.86
9931001

9941002
####Udemy Two Pointers
9951003

9961004
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
9971005
|-|-|-|-|-|-
1006+
| 0042 |[Trapping Rain Water](src/main/js/g0001_0100/s0042_trapping_rain_water/solution.js)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
9981007
| 0015 |[3Sum](src/main/js/g0001_0100/s0015_3sum/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 31 | 91.92
9991008

10001009
####Udemy Famous Algorithm
@@ -1046,7 +1055,9 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
10461055
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
10471056
|-|-|-|-|-|-
10481057
| 0022 |[Generate Parentheses](src/main/js/g0001_0100/s0022_generate_parentheses/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 0 | 100.00
1058+
| 0039 |[Combination Sum](src/main/js/g0001_0100/s0039_combination_sum/solution.js)| Medium | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 98.51
10491059
| 0017 |[Letter Combinations of a Phone Number](src/main/js/g0001_0100/s0017_letter_combinations_of_a_phone_number/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 0 | 100.00
1060+
| 0046 |[Permutations](src/main/js/g0001_0100/s0046_permutations/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 0 | 100.00
10501061

10511062
####Udemy Bit Manipulation
10521063

@@ -1249,6 +1260,11 @@ JavaScript-based LeetCode algorithm problem solutions, regularly updated.
12491260

12501261
| # | Title | Difficulty | Tag | Time, ms | Time, %
12511262
|------|----------------|-------------|-------------|----------|---------
1263+
| 0046 |[Permutations](src/main/js/g0001_0100/s0046_permutations/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Backtracking, Algorithm_I_Day_11_Recursion_Backtracking, Level_2_Day_20_Brute_Force/Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(n\*n!)_Space_O(n+n!) | 0 | 100.00
1264+
| 0045 |[Jump Game II](src/main/js/g0001_0100/s0045_jump_game_ii/solution.js)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Algorithm_II_Day_13_Dynamic_Programming, Dynamic_Programming_I_Day_4, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
1265+
| 0042 |[Trapping Rain Water](src/main/js/g0001_0100/s0042_trapping_rain_water/solution.js)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Two_Pointers, Stack, Monotonic_Stack, Dynamic_Programming_I_Day_9, Udemy_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 0 | 100.00
1266+
| 0041 |[First Missing Positive](src/main/js/g0001_0100/s0041_first_missing_positive/solution.js)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Udemy_Arrays, Big_O_Time_O(n)_Space_O(n) | 1 | 98.86
1267+
| 0039 |[Combination Sum](src/main/js/g0001_0100/s0039_combination_sum/solution.js)| Medium | Top_100_Liked_Questions, Array, Backtracking, Algorithm_II_Day_10_Recursion_Backtracking, Level_2_Day_20_Brute_Force/Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(2^n)_Space_O(n+2^n) | 1 | 98.51
12521268
| 0035 |[Search Insert Position](src/main/js/g0001_0100/s0035_search_insert_position/solution.js)| Easy | Top_100_Liked_Questions, Array, Binary_Search, Algorithm_I_Day_1_Binary_Search, Binary_Search_I_Day_2, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
12531269
| 0034 |[Find First and Last Position of Element in Sorted Array](src/main/js/g0001_0100/s0034_find_first_and_last_position_of_element_in_sorted_array/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Algorithm_II_Day_1_Binary_Search, Binary_Search_I_Day_5, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
12541270
| 0033 |[Search in Rotated Sorted Array](src/main/js/g0001_0100/s0033_search_in_rotated_sorted_array/solution.js)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Binary_Search, Algorithm_II_Day_1_Binary_Search, Binary_Search_I_Day_11, Level_2_Day_8_Binary_Search, Udemy_Binary_Search, Big_O_Time_O(log_n)_Space_O(1) | 0 | 100.00
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
39\. Combination Sum
2+
3+
Medium
4+
5+
Given an array of**distinct** integers`candidates` and a target integer`target`, return_a list of all**unique combinations** of_`candidates`_where the chosen numbers sum to_`target`_._ You may return the combinations in**any order**.
6+
7+
The**same** number may be chosen from`candidates` an**unlimited number of times**. Two combinations are unique if the frequency of at least one of the chosen numbers is different.
8+
9+
It is**guaranteed** that the number of unique combinations that sum up to`target` is less than`150` combinations for the given input.
10+
11+
**Example 1:**
12+
13+
**Input:** candidates =[2,3,6,7], target = 7
14+
15+
**Output:**[[2,2,3],[7]]
16+
17+
**Explanation:**
18+
2 and 3 are candidates, and 2 + 2 + 3 = 7. Note that 2 can be used multiple times.
19+
20+
7 is a candidate, and 7 = 7.
21+
22+
These are the only two combinations.
23+
24+
**Example 2:**
25+
26+
**Input:** candidates =[2,3,5], target = 8
27+
28+
**Output:**[[2,2,2,2],[2,3,3],[3,5]]
29+
30+
**Example 3:**
31+
32+
**Input:** candidates =[2], target = 1
33+
34+
**Output:**[]
35+
36+
**Constraints:**
37+
38+
*`1 <= candidates.length <= 30`
39+
*`1 <= candidates[i] <= 200`
40+
* All elements of`candidates` are**distinct**.
41+
*`1 <= target <= 500`
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// #Medium #Top_100_Liked_Questions #Array #Backtracking #Algorithm_II_Day_10_Recursion_Backtracking
2+
// #Level_2_Day_20_Brute_Force/Backtracking #Udemy_Backtracking/Recursion
3+
// #Big_O_Time_O(2^n)_Space_O(n+2^n) #2024_12_08_Time_1_ms_(98.51%)_Space_54.6_MB_(59.25%)
4+
5+
/**
6+
*@param {number[]} candidates
7+
*@param {number} target
8+
*@return {number[][]}
9+
*/
10+
varcombinationSum=function(candidates,target){
11+
constans=[]
12+
constsubList=[]
13+
14+
constcombinationSumRec=(n,candidates,target,subList,ans)=>{
15+
if(target===0||n===0){
16+
if(target===0){
17+
ans.push([...subList])// Create a copy of subList
18+
}
19+
return
20+
}
21+
22+
if(target-candidates[n-1]>=0){
23+
subList.push(candidates[n-1])
24+
combinationSumRec(n,candidates,target-candidates[n-1],subList,ans)
25+
subList.pop()// Backtracking step
26+
}
27+
28+
combinationSumRec(n-1,candidates,target,subList,ans)
29+
}
30+
31+
combinationSumRec(candidates.length,candidates,target,subList,ans)
32+
returnans
33+
};
34+
35+
export{combinationSum}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
41\. First Missing Positive
2+
3+
Hard
4+
5+
Given an unsorted integer array`nums`, return the smallest missing positive integer.
6+
7+
You must implement an algorithm that runs in`O(n)` time and uses constant extra space.
8+
9+
**Example 1:**
10+
11+
**Input:** nums =[1,2,0]
12+
13+
**Output:** 3
14+
15+
**Explanation:** The numbers in the range[1,2] are all in the array.
16+
17+
**Example 2:**
18+
19+
**Input:** nums =[3,4,-1,1]
20+
21+
**Output:** 2
22+
23+
**Explanation:** 1 is in the array but 2 is missing.
24+
25+
**Example 3:**
26+
27+
**Input:** nums =[7,8,9,11,12]
28+
29+
**Output:** 1
30+
31+
**Explanation:** The smallest positive integer 1 is missing.
32+
33+
**Constraints:**
34+
35+
* <code>1 <= nums.length <= 10<sup>5</sup></code>
36+
* <code>-2<sup>31</sup> <= nums[i] <= 2<sup>31</sup> - 1</code>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Hash_Table #Udemy_Arrays
2+
// #Big_O_Time_O(n)_Space_O(n) #2024_12_08_Time_1_ms_(98.86%)_Space_56.6_MB_(89.65%)
3+
4+
/**
5+
*@param {number[]} nums
6+
*@return {number}
7+
*/
8+
varfirstMissingPositive=function(nums){
9+
for(leti=0;i<nums.length;i++){
10+
while(
11+
nums[i]>0&&
12+
nums[i]<=nums.length&&
13+
nums[nums[i]-1]!==nums[i]
14+
){
15+
// Swap nums[i] with nums[nums[i] - 1]
16+
lettemp=nums[nums[i]-1]
17+
nums[nums[i]-1]=nums[i]
18+
nums[i]=temp
19+
}
20+
}
21+
22+
for(leti=0;i<nums.length;i++){
23+
if(nums[i]!==i+1){
24+
returni+1
25+
}
26+
}
27+
28+
returnnums.length+1
29+
};
30+
31+
export{firstMissingPositive}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
42\. Trapping Rain Water
2+
3+
Hard
4+
5+
Given`n` non-negative integers representing an elevation map where the width of each bar is`1`, compute how much water it can trap after raining.
6+
7+
**Example 1:**
8+
9+
![](https://assets.leetcode.com/uploads/2018/10/22/rainwatertrap.png)
10+
11+
**Input:** height =[0,1,0,2,1,0,1,3,2,1,2,1]
12+
13+
**Output:** 6
14+
15+
**Explanation:** The above elevation map (black section) is represented by array[0,1,0,2,1,0,1,3,2,1,2,1]. In this case, 6 units of rain water (blue section) are being trapped.
16+
17+
**Example 2:**
18+
19+
**Input:** height =[4,2,0,3,2,5]
20+
21+
**Output:** 9
22+
23+
**Constraints:**
24+
25+
*`n == height.length`
26+
* <code>1 <= n <= 2 * 10<sup>4</sup></code>
27+
* <code>0 <= height[i] <= 10<sup>5</sup></code>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// #Hard #Top_100_Liked_Questions #Top_Interview_Questions #Array #Dynamic_Programming #Two_Pointers
2+
// #Stack #Monotonic_Stack #Dynamic_Programming_I_Day_9 #Udemy_Two_Pointers
3+
// #Big_O_Time_O(n)_Space_O(1) #2024_12_08_Time_0_ms_(100.00%)_Space_51.2_MB_(88.05%)
4+
5+
/**
6+
*@param {number[]} height
7+
*@return {number}
8+
*/
9+
vartrap=function(height){
10+
letl=0
11+
letr=height.length-1
12+
letres=0
13+
letlowerWall=0
14+
15+
while(l<r){
16+
letlVal=height[l]
17+
letrVal=height[r]
18+
19+
// Determine the lower wall
20+
if(lVal<rVal){
21+
// Update the lower wall based on the left pointer
22+
lowerWall=Math.max(lVal,lowerWall)
23+
// Add water trapped at the current position
24+
res+=lowerWall-lVal
25+
// Move the left pointer
26+
l++
27+
}else{
28+
// Update the lower wall based on the right pointer
29+
lowerWall=Math.max(rVal,lowerWall)
30+
// Add water trapped at the current position
31+
res+=lowerWall-rVal
32+
// Move the right pointer
33+
r--
34+
}
35+
}
36+
37+
returnres
38+
};
39+
40+
export{trap}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
45\. Jump Game II
2+
3+
Medium
4+
5+
Given an array of non-negative integers`nums`, you are initially positioned at the first index of the array.
6+
7+
Each element in the array represents your maximum jump length at that position.
8+
9+
Your goal is to reach the last index in the minimum number of jumps.
10+
11+
You can assume that you can always reach the last index.
12+
13+
**Example 1:**
14+
15+
**Input:** nums =[2,3,1,1,4]
16+
17+
**Output:** 2
18+
19+
**Explanation:** The minimum number of jumps to reach the last index is 2. Jump 1 step from index 0 to 1, then 3 steps to the last index.
20+
21+
**Example 2:**
22+
23+
**Input:** nums =[2,3,0,1,4]
24+
25+
**Output:** 2
26+
27+
**Constraints:**
28+
29+
* <code>1 <= nums.length <= 10<sup>4</sup></code>
30+
*`0 <= nums[i] <= 1000`
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// #Medium #Top_100_Liked_Questions #Array #Dynamic_Programming #Greedy
2+
// #Algorithm_II_Day_13_Dynamic_Programming #Dynamic_Programming_I_Day_4
3+
// #Big_O_Time_O(n)_Space_O(1) #2024_12_08_Time_0_ms_(100.00%)_Space_51.5_MB_(23.51%)
4+
5+
/**
6+
*@param {number[]} nums
7+
*@return {number}
8+
*/
9+
vargetMax=function(nums,l,r){
10+
letmax=-1
11+
for(leti=l;i<=r;i++){
12+
max=Math.max(max,i+nums[i])
13+
}
14+
returnmax
15+
};
16+
17+
varjump=function(nums){
18+
letl=0
19+
letr=0
20+
letjumps=0
21+
22+
while(r<nums.length-1){
23+
letprev=r
24+
r=getMax(nums,l,r)
25+
l=prev+1
26+
jumps++
27+
}
28+
29+
returnjumps
30+
};
31+
32+
export{jump}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
46\. Permutations
2+
3+
Medium
4+
5+
Given an array`nums` of distinct integers, return_all the possible permutations_. You can return the answer in**any order**.
6+
7+
**Example 1:**
8+
9+
**Input:** nums =[1,2,3]
10+
11+
**Output:**[[1,2,3],[1,3,2],[2,1,3],[2,3,1],[3,1,2],[3,2,1]]
12+
13+
**Example 2:**
14+
15+
**Input:** nums =[0,1]
16+
17+
**Output:**[[0,1],[1,0]]
18+
19+
**Example 3:**
20+
21+
**Input:** nums =[1]
22+
23+
**Output:**[[1]]
24+
25+
**Constraints:**
26+
27+
*`1 <= nums.length <= 6`
28+
*`-10 <= nums[i] <= 10`
29+
* All the integers of`nums` are**unique**.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp