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

Commit3e01cfd

Browse files
authored
Added tasks 11-25
1 parentc71be14 commit3e01cfd

File tree

35 files changed

+951
-3
lines changed

35 files changed

+951
-3
lines changed

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
.idea/
22
*.iml
3+
Gemfile.lock

‎README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
4242

4343
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
4444
|-|-|-|-|-|-
45+
| 0015 |[3Sum](src/main/ruby/g0001_0100/s0015_3sum/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 659 | 83.74
4546

4647
####Day 4 Two Pointers
4748

4849
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
4950
|-|-|-|-|-|-
51+
| 0011 |[Container With Most Water](src/main/ruby/g0001_0100/s0011_container_with_most_water/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 114 | 95.98
5052

5153
####Day 5 Sliding Window
5254

@@ -82,6 +84,8 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
8284

8385
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
8486
|-|-|-|-|-|-
87+
| 0017 |[Letter Combinations of a Phone Number](src/main/ruby/g0001_0100/s0017_letter_combinations_of_a_phone_number/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 49 | 93.94
88+
| 0022 |[Generate Parentheses](src/main/ruby/g0001_0100/s0022_generate_parentheses/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 43 | 100.00
8589

8690
####Day 12 Dynamic Programming
8791

@@ -711,6 +715,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
711715

712716
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
713717
|-|-|-|-|-|-
718+
| 0021 |[Merge Two Sorted Lists](src/main/ruby/g0001_0100/s0021_merge_two_sorted_lists/solution.rb)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 66 | 59.01
714719

715720
####Day 4 Linked List
716721

@@ -789,6 +794,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
789794

790795
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
791796
|-|-|-|-|-|-
797+
| 0019 |[Remove Nth Node From End of List](src/main/ruby/g0001_0100/s0019_remove_nth_node_from_end_of_list/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 51 | 95.27
792798

793799
####Day 4 Linked List
794800

@@ -890,6 +896,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
890896
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
891897
|-|-|-|-|-|-
892898
| 0003 |[Longest Substring Without Repeating Characters](src/main/ruby/g0001_0100/s0003_longest_substring_without_repeating_characters/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1) | 94 | 85.62
899+
| 0020 |[Valid Parentheses](src/main/ruby/g0001_0100/s0020_valid_parentheses/solution.rb)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 53 | 90.52
893900
| 0005 |[Longest Palindromic Substring](src/main/ruby/g0001_0100/s0005_longest_palindromic_substring/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 117 | 98.63
894901

895902
####Udemy Binary Search
@@ -907,6 +914,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
907914

908915
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
909916
|-|-|-|-|-|-
917+
| 0015 |[3Sum](src/main/ruby/g0001_0100/s0015_3sum/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 659 | 83.74
910918

911919
####Udemy Famous Algorithm
912920

@@ -927,6 +935,9 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
927935

928936
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
929937
|-|-|-|-|-|-
938+
| 0024 |[Swap Nodes in Pairs](src/main/ruby/g0001_0100/s0024_swap_nodes_in_pairs/solution.rb)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 59 | 76.00
939+
| 0021 |[Merge Two Sorted Lists](src/main/ruby/g0001_0100/s0021_merge_two_sorted_lists/solution.rb)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 66 | 59.01
940+
| 0025 |[Reverse Nodes in k-Group](src/main/ruby/g0001_0100/s0025_reverse_nodes_in_k_group/solution.rb)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 62 | 91.67
930941

931942
####Udemy Tree Stack Queue
932943

@@ -953,6 +964,8 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
953964

954965
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
955966
|-|-|-|-|-|-
967+
| 0022 |[Generate Parentheses](src/main/ruby/g0001_0100/s0022_generate_parentheses/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Big_O_Time_O(2^n)_Space_O(n) | 43 | 100.00
968+
| 0017 |[Letter Combinations of a Phone Number](src/main/ruby/g0001_0100/s0017_letter_combinations_of_a_phone_number/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Big_O_Time_O(4^n)_Space_O(n) | 49 | 93.94
956969

957970
####Udemy Bit Manipulation
958971

@@ -1001,6 +1014,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
10011014

10021015
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
10031016
|-|-|-|-|-|-
1017+
| 0021 |[Merge Two Sorted Lists](src/main/ruby/g0001_0100/s0021_merge_two_sorted_lists/solution.rb)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 66 | 59.01
10041018

10051019
####Day 8 Linked List
10061020

@@ -1011,6 +1025,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
10111025

10121026
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
10131027
|-|-|-|-|-|-
1028+
| 0020 |[Valid Parentheses](src/main/ruby/g0001_0100/s0020_valid_parentheses/solution.rb)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 53 | 90.52
10141029

10151030
####Day 10 Tree
10161031

@@ -1043,6 +1058,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
10431058

10441059
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
10451060
|-|-|-|-|-|-
1061+
| 0015 |[3Sum](src/main/ruby/g0001_0100/s0015_3sum/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 659 | 83.74
10461062

10471063
####Day 2 Array
10481064

@@ -1100,11 +1116,13 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
11001116

11011117
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
11021118
|-|-|-|-|-|-
1119+
| 0024 |[Swap Nodes in Pairs](src/main/ruby/g0001_0100/s0024_swap_nodes_in_pairs/solution.rb)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(1) | 59 | 76.00
11031120

11041121
####Day 13 Linked List
11051122

11061123
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
11071124
|-|-|-|-|-|-
1125+
| 0025 |[Reverse Nodes in k-Group](src/main/ruby/g0001_0100/s0025_reverse_nodes_in_k_group/solution.rb)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Big_O_Time_O(n)_Space_O(k) | 62 | 91.67
11081126

11091127
####Day 14 Stack Queue
11101128

@@ -1172,6 +1190,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
11721190

11731191
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
11741192
|-|-|-|-|-|-
1193+
| 0019 |[Remove Nth Node From End of List](src/main/ruby/g0001_0100/s0019_remove_nth_node_from_end_of_list/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Big_O_Time_O(L)_Space_O(L) | 51 | 95.27
11751194

11761195
####Day 6 Sliding Window
11771196

@@ -1198,6 +1217,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
11981217

11991218
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
12001219
|-|-|-|-|-|-
1220+
| 0021 |[Merge Two Sorted Lists](src/main/ruby/g0001_0100/s0021_merge_two_sorted_lists/solution.rb)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Big_O_Time_O(m+n)_Space_O(m+n) | 66 | 59.01
12011221

12021222
####Day 11 Recursion Backtracking
12031223

@@ -1223,6 +1243,16 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
12231243

12241244
| # | Title | Difficulty | Tag | Time, ms | Time, %
12251245
|------|----------------|-------------|-------------|----------|---------
1246+
| 0025 |[Reverse Nodes in k-Group](src/main/ruby/g0001_0100/s0025_reverse_nodes_in_k_group/solution.rb)| Hard | Top_100_Liked_Questions, Linked_List, Recursion, Data_Structure_II_Day_13_Linked_List, Udemy_Linked_List, Big_O_Time_O(n)_Space_O(k) | 62 | 91.67
1247+
| 0024 |[Swap Nodes in Pairs](src/main/ruby/g0001_0100/s0024_swap_nodes_in_pairs/solution.rb)| Medium | Top_100_Liked_Questions, Linked_List, Recursion, Data_Structure_II_Day_12_Linked_List, Udemy_Linked_List, Big_O_Time_O(n)_Space_O(1) | 59 | 76.00
1248+
| 0023 |[Merge k Sorted Lists](src/main/ruby/g0001_0100/s0023_merge_k_sorted_lists/solution.rb)| 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)) | 76 | 87.95
1249+
| 0022 |[Generate Parentheses](src/main/ruby/g0001_0100/s0022_generate_parentheses/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Backtracking, Algorithm_II_Day_11_Recursion_Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(2^n)_Space_O(n) | 43 | 100.00
1250+
| 0021 |[Merge Two Sorted Lists](src/main/ruby/g0001_0100/s0021_merge_two_sorted_lists/solution.rb)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Linked_List, Recursion, Data_Structure_I_Day_7_Linked_List, Algorithm_I_Day_10_Recursion_Backtracking, Level_1_Day_3_Linked_List, Udemy_Linked_List, Big_O_Time_O(m+n)_Space_O(m+n) | 66 | 59.01
1251+
| 0020 |[Valid Parentheses](src/main/ruby/g0001_0100/s0020_valid_parentheses/solution.rb)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Data_Structure_I_Day_9_Stack_Queue, Udemy_Strings, Big_O_Time_O(n)_Space_O(n) | 53 | 90.52
1252+
| 0019 |[Remove Nth Node From End of List](src/main/ruby/g0001_0100/s0019_remove_nth_node_from_end_of_list/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Two_Pointers, Linked_List, Algorithm_I_Day_5_Two_Pointers, Level_2_Day_3_Linked_List, Big_O_Time_O(L)_Space_O(L) | 51 | 95.27
1253+
| 0017 |[Letter Combinations of a Phone Number](src/main/ruby/g0001_0100/s0017_letter_combinations_of_a_phone_number/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Backtracking, Algorithm_II_Day_11_Recursion_Backtracking, Udemy_Backtracking/Recursion, Big_O_Time_O(4^n)_Space_O(n) | 49 | 93.94
1254+
| 0015 |[3Sum](src/main/ruby/g0001_0100/s0015_3sum/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Two_Pointers, Data_Structure_II_Day_1_Array, Algorithm_II_Day_3_Two_Pointers, Udemy_Two_Pointers, Big_O_Time_O(n\*log(n))_Space_O(n^2) | 659 | 83.74
1255+
| 0011 |[Container With Most Water](src/main/ruby/g0001_0100/s0011_container_with_most_water/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Greedy, Two_Pointers, Algorithm_II_Day_4_Two_Pointers, Big_O_Time_O(n)_Space_O(1) | 114 | 95.98
12261256
| 0010 |[Regular Expression Matching](src/main/ruby/g0001_0100/s0010_regular_expression_matching/solution.rb)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Recursion, Udemy_Dynamic_Programming, Big_O_Time_O(m\*n)_Space_O(m\*n) | 66 | 94.44
12271257
| 0009 |[Palindrome Number](src/main/ruby/g0001_0100/s0009_palindrome_number/solution.rb)| Easy | Math, Udemy_Integers | 83 | 74.19
12281258
| 0008 |[String to Integer (atoi)](src/main/ruby/g0001_0100/s0008_string_to_integer_atoi/solution.rb)| Medium | Top_Interview_Questions, String | 67 | 67.26

‎src/main/ruby/com_github_leetcode/list_node.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
classListNode
33
attr_accessor:val,:next
44

5-
definitialize(x)
5+
definitialize(x=0,_next=nil)
66
@val=x
7-
@next=nil
7+
@next=_next
88
end
99

1010
defto_a
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
11\. Container With Most Water
2+
3+
Medium
4+
5+
Given`n` non-negative integers <code>a<sub>1</sub>, a<sub>2</sub>, ..., a<sub>n</sub></code> , where each represents a point at coordinate <code>(i, a<sub>i</sub>)</code>.`n` vertical lines are drawn such that the two endpoints of the line`i` is at <code>(i, a<sub>i</sub>)</code> and`(i, 0)`. Find two lines, which, together with the x-axis forms a container, such that the container contains the most water.
6+
7+
**Notice** that you may not slant the container.
8+
9+
**Example 1:**
10+
11+
![](https://s3-lc-upload.s3.amazonaws.com/uploads/2018/07/17/question_11.jpg)
12+
13+
**Input:** height =[1,8,6,2,5,4,8,3,7]
14+
15+
**Output:** 49
16+
17+
**Explanation:** The above vertical lines are represented by array[1,8,6,2,5,4,8,3,7]. In this case, the max area of water (blue section) the container can contain is 49.
18+
19+
**Example 2:**
20+
21+
**Input:** height =[1,1]
22+
23+
**Output:** 1
24+
25+
**Example 3:**
26+
27+
**Input:** height =[4,3,2,1,4]
28+
29+
**Output:** 16
30+
31+
**Example 4:**
32+
33+
**Input:** height =[1,2,1]
34+
35+
**Output:** 2
36+
37+
**Constraints:**
38+
39+
*`n == height.length`
40+
* <code>2 <= n <= 10<sup>5</sup></code>
41+
* <code>0 <= height[i] <= 10<sup>4</sup></code>
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Greedy #Two_Pointers
2+
# #Algorithm_II_Day_4_Two_Pointers #Big_O_Time_O(n)_Space_O(1)
3+
# #2023_11_17_Time_114_ms_(95.98%)_Space_217.5_MB_(71.21%)
4+
5+
# @param {Integer[]} height
6+
# @return {Integer}
7+
defmax_area(height)
8+
max_area= -1
9+
left=0
10+
right=height.length -1
11+
12+
whileleft <right
13+
ifheight[left] <height[right]
14+
max_area=[max_area,height[left] *(right -left)].max
15+
left +=1
16+
else
17+
max_area=[max_area,height[right] *(right -left)].max
18+
right -=1
19+
end
20+
end
21+
22+
max_area
23+
end
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
15\. 3Sum
2+
3+
Medium
4+
5+
Given an integer array nums, return all the triplets`[nums[i], nums[j], nums[k]]` such that`i != j`,`i != k`, and`j != k`, and`nums[i] + nums[j] + nums[k] == 0`.
6+
7+
Notice that the solution set must not contain duplicate triplets.
8+
9+
**Example 1:**
10+
11+
**Input:** nums =[-1,0,1,2,-1,-4]
12+
13+
**Output:**[[-1,-1,2],[-1,0,1]]
14+
15+
**Example 2:**
16+
17+
**Input:** nums =[]
18+
19+
**Output:**[]
20+
21+
**Example 3:**
22+
23+
**Input:** nums =[0]
24+
25+
**Output:**[]
26+
27+
**Constraints:**
28+
29+
*`0 <= nums.length <= 3000`
30+
* <code>-10<sup>5</sup> <= nums[i] <= 10<sup>5</sup></code>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Sorting #Two_Pointers
2+
# #Data_Structure_II_Day_1_Array #Algorithm_II_Day_3_Two_Pointers #Udemy_Two_Pointers
3+
# #Big_O_Time_O(n*log(n))_Space_O(n^2) #2023_11_17_Time_659_ms_(83.74%)_Space_214.1_MB_(59.36%)
4+
5+
# @param {Integer[]} nums
6+
# @return {Integer[][]}
7+
defthree_sum(nums)
8+
nums=nums.sort
9+
rs=[]
10+
nums.each.with_indexdo |num,i|
11+
ifi >0 &&num ==nums[i -1]
12+
next
13+
end
14+
l,r=i +1,nums.size -1
15+
16+
whilel <r
17+
sum=num +nums[l] +nums[r]
18+
ifsum >0
19+
r -=1
20+
elsifsum <0
21+
l +=1
22+
else
23+
rs <<[num,nums[l],nums[r]]
24+
l +=1
25+
whilenums[l] ==nums[l -1] &&l <r
26+
l +=1
27+
end
28+
end
29+
end
30+
end
31+
32+
rs
33+
end
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
17\. Letter Combinations of a Phone Number
2+
3+
Medium
4+
5+
Given a string containing digits from`2-9` inclusive, return all possible letter combinations that the number could represent. Return the answer in**any order**.
6+
7+
A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.
8+
9+
![](https://upload.wikimedia.org/wikipedia/commons/thumb/7/73/Telephone-keypad2.svg/200px-Telephone-keypad2.svg.png)
10+
11+
**Example 1:**
12+
13+
**Input:** digits = "23"
14+
15+
**Output:**["ad","ae","af","bd","be","bf","cd","ce","cf"]
16+
17+
**Example 2:**
18+
19+
**Input:** digits = ""
20+
21+
**Output:**[]
22+
23+
**Example 3:**
24+
25+
**Input:** digits = "2"
26+
27+
**Output:**["a","b","c"]
28+
29+
**Constraints:**
30+
31+
*`0 <= digits.length <= 4`
32+
*`digits[i]` is a digit in the range`['2', '9']`.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# #Medium #Top_100_Liked_Questions #Top_Interview_Questions #String #Hash_Table #Backtracking
2+
# #Algorithm_II_Day_11_Recursion_Backtracking #Udemy_Backtracking/Recursion
3+
# #Big_O_Time_O(4^n)_Space_O(n) #2023_11_17_Time_49_ms_(93.94%)_Space_210.9_MB_(97.73%)
4+
5+
# @param {String} digits
6+
# @return {String[]}
7+
defletter_combinations(digits)
8+
return[]ifdigits.empty?
9+
10+
letters=["","","abc","def","ghi","jkl","mno","pqrs","tuv","wxyz"]
11+
ans=[]
12+
find_combinations(0,digits,letters,"",ans)
13+
ans
14+
end
15+
16+
private
17+
18+
deffind_combinations(start,nums,letters,curr,ans)
19+
ifcurr.length ==nums.length
20+
ans <<curr
21+
return
22+
end
23+
24+
(start...nums.length).eachdo |i|
25+
n=nums[i].to_i
26+
letters[n].each_chardo |ch|
27+
find_combinations(i +1,nums,letters,curr +ch,ans)
28+
end
29+
end
30+
end
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
19\. Remove Nth Node From End of List
2+
3+
Medium
4+
5+
Given the`head` of a linked list, remove the`nth` node from the end of the list and return its head.
6+
7+
**Example 1:**
8+
9+
![](https://assets.leetcode.com/uploads/2020/10/03/remove_ex1.jpg)
10+
11+
**Input:** head =[1,2,3,4,5], n = 2
12+
13+
**Output:**[1,2,3,5]
14+
15+
**Example 2:**
16+
17+
**Input:** head =[1], n = 1
18+
19+
**Output:**[]
20+
21+
**Example 3:**
22+
23+
**Input:** head =[1,2], n = 1
24+
25+
**Output:**[1]
26+
27+
**Constraints:**
28+
29+
* The number of nodes in the list is`sz`.
30+
*`1 <= sz <= 30`
31+
*`0 <= Node.val <= 100`
32+
*`1 <= n <= sz`
33+
34+
**Follow up:** Could you do this in one pass?

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp