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

Commite1365ed

Browse files
authored
Added tasks 48-72
1 parentff4ff78 commite1365ed

File tree

31 files changed

+798
-0
lines changed

31 files changed

+798
-0
lines changed

‎README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,14 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
9494

9595
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
9696
|-|-|-|-|-|-
97+
| 0055 |[Jump Game](src/main/ruby/g0001_0100/s0055_jump_game/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 88 | 95.88
9798

9899
####Day 13 Dynamic Programming
99100

100101
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
101102
|-|-|-|-|-|-
102103
| 0045 |[Jump Game II](src/main/ruby/g0001_0100/s0045_jump_game_ii/solution.rb)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 68 | 75.23
104+
| 0062 |[Unique Paths](src/main/ruby/g0001_0100/s0062_unique_paths/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 50 | 91.92
103105

104106
####Day 14 Dynamic Programming
105107

@@ -126,6 +128,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
126128

127129
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
128130
|-|-|-|-|-|-
131+
| 0072 |[Edit Distance](src/main/ruby/g0001_0100/s0072_edit_distance/solution.rb)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 139 | 73.91
129132

130133
####Day 19 Bit Manipulation
131134

@@ -320,6 +323,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
320323

321324
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
322325
|-|-|-|-|-|-
326+
| 0070 |[Climbing Stairs](src/main/ruby/g0001_0100/s0070_climbing_stairs/solution.rb)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 48 | 96.01
323327

324328
####Day 3
325329

@@ -330,12 +334,14 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
330334

331335
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
332336
|-|-|-|-|-|-
337+
| 0055 |[Jump Game](src/main/ruby/g0001_0100/s0055_jump_game/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 88 | 95.88
333338
| 0045 |[Jump Game II](src/main/ruby/g0001_0100/s0045_jump_game_ii/solution.rb)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 68 | 75.23
334339

335340
####Day 5
336341

337342
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
338343
|-|-|-|-|-|-
344+
| 0053 |[Maximum Subarray](src/main/ruby/g0001_0100/s0053_maximum_subarray/solution.rb)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 125 | 81.22
339345

340346
####Day 6
341347

@@ -387,11 +393,13 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
387393

388394
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
389395
|-|-|-|-|-|-
396+
| 0062 |[Unique Paths](src/main/ruby/g0001_0100/s0062_unique_paths/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 50 | 91.92
390397

391398
####Day 16
392399

393400
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
394401
|-|-|-|-|-|-
402+
| 0064 |[Minimum Path Sum](src/main/ruby/g0001_0100/s0064_minimum_path_sum/solution.rb)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 78 | 52.50
395403

396404
####Day 17
397405

@@ -408,6 +416,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
408416

409417
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
410418
|-|-|-|-|-|-
419+
| 0072 |[Edit Distance](src/main/ruby/g0001_0100/s0072_edit_distance/solution.rb)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 139 | 73.91
411420

412421
####Day 20
413422

@@ -517,6 +526,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
517526

518527
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
519528
|-|-|-|-|-|-
529+
| 0048 |[Rotate Image](src/main/ruby/g0001_0100/s0048_rotate_image/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 50 | 93.64
520530

521531
####Day 8
522532

@@ -537,6 +547,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
537547

538548
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
539549
|-|-|-|-|-|-
550+
| 0049 |[Group Anagrams](src/main/ruby/g0001_0100/s0049_group_anagrams/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 154 | 83.69
540551

541552
####Day 12
542553

@@ -760,11 +771,13 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
760771

761772
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
762773
|-|-|-|-|-|-
774+
| 0070 |[Climbing Stairs](src/main/ruby/g0001_0100/s0070_climbing_stairs/solution.rb)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 48 | 96.01
763775

764776
####Day 11 Dynamic Programming
765777

766778
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
767779
|-|-|-|-|-|-
780+
| 0062 |[Unique Paths](src/main/ruby/g0001_0100/s0062_unique_paths/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 50 | 91.92
768781

769782
####Day 12 Sliding Window/Two Pointer
770783

@@ -876,6 +889,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
876889

877890
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
878891
|-|-|-|-|-|-
892+
| 0056 |[Merge Intervals](src/main/ruby/g0001_0100/s0056_merge_intervals/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 103 | 74.70
879893

880894
####Day 18 Stack
881895

@@ -910,6 +924,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
910924
| 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
911925
| 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
912926
| 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
927+
| 0049 |[Group Anagrams](src/main/ruby/g0001_0100/s0049_group_anagrams/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 154 | 83.69
913928

914929
####Udemy Binary Search
915930

@@ -922,6 +937,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
922937
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
923938
|-|-|-|-|-|-
924939
| 0001 |[Two Sum](src/main/ruby/g0001_0100/s0001_two_sum/solution.rb)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 57 | 89.38
940+
| 0055 |[Jump Game](src/main/ruby/g0001_0100/s0055_jump_game/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 88 | 95.88
925941
| 0041 |[First Missing Positive](src/main/ruby/g0001_0100/s0041_first_missing_positive/solution.rb)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 130 | 65.63
926942

927943
####Udemy Two Pointers
@@ -935,6 +951,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
935951

936952
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
937953
|-|-|-|-|-|-
954+
| 0053 |[Maximum Subarray](src/main/ruby/g0001_0100/s0053_maximum_subarray/solution.rb)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 125 | 81.22
938955

939956
####Udemy Sorting Algorithms
940957

@@ -945,6 +962,8 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
945962

946963
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
947964
|-|-|-|-|-|-
965+
| 0048 |[Rotate Image](src/main/ruby/g0001_0100/s0048_rotate_image/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 50 | 93.64
966+
| 0056 |[Merge Intervals](src/main/ruby/g0001_0100/s0056_merge_intervals/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 103 | 74.70
948967

949968
####Udemy Linked List
950969

@@ -973,6 +992,9 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
973992

974993
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
975994
|-|-|-|-|-|-
995+
| 0070 |[Climbing Stairs](src/main/ruby/g0001_0100/s0070_climbing_stairs/solution.rb)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 48 | 96.01
996+
| 0064 |[Minimum Path Sum](src/main/ruby/g0001_0100/s0064_minimum_path_sum/solution.rb)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 78 | 52.50
997+
| 0072 |[Edit Distance](src/main/ruby/g0001_0100/s0072_edit_distance/solution.rb)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 139 | 73.91
976998
| 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, Big_O_Time_O(m\*n)_Space_O(m\*n) | 66 | 94.44
977999

9781000
####Udemy Backtracking/Recursion
@@ -1000,6 +1022,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
10001022

10011023
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
10021024
|-|-|-|-|-|-
1025+
| 0053 |[Maximum Subarray](src/main/ruby/g0001_0100/s0053_maximum_subarray/solution.rb)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 125 | 81.22
10031026

10041027
####Day 2 Array
10051028

@@ -1081,11 +1104,13 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
10811104

10821105
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
10831106
|-|-|-|-|-|-
1107+
| 0056 |[Merge Intervals](src/main/ruby/g0001_0100/s0056_merge_intervals/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 103 | 74.70
10841108

10851109
####Day 3 Array
10861110

10871111
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
10881112
|-|-|-|-|-|-
1113+
| 0048 |[Rotate Image](src/main/ruby/g0001_0100/s0048_rotate_image/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 50 | 93.64
10891114

10901115
####Day 4 Array
10911116

@@ -1111,6 +1136,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
11111136

11121137
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
11131138
|-|-|-|-|-|-
1139+
| 0049 |[Group Anagrams](src/main/ruby/g0001_0100/s0049_group_anagrams/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 154 | 83.69
11141140

11151141
####Day 9 String
11161142

@@ -1247,6 +1273,7 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
12471273

12481274
|<!----> |<!----> |<!----> |<!----> |<!----> |<!---->
12491275
|-|-|-|-|-|-
1276+
| 0070 |[Climbing Stairs](src/main/ruby/g0001_0100/s0070_climbing_stairs/solution.rb)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 48 | 96.01
12501277

12511278
####Day 13 Bit Manipulation
12521279

@@ -1262,6 +1289,16 @@ Ruby-based LeetCode algorithm problem solutions, regularly updated.
12621289

12631290
| # | Title | Difficulty | Tag | Time, ms | Time, %
12641291
|------|----------------|-------------|-------------|----------|---------
1292+
| 0072 |[Edit Distance](src/main/ruby/g0001_0100/s0072_edit_distance/solution.rb)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Algorithm_II_Day_18_Dynamic_Programming, Dynamic_Programming_I_Day_19, Udemy_Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 139 | 73.91
1293+
| 0070 |[Climbing Stairs](src/main/ruby/g0001_0100/s0070_climbing_stairs/solution.rb)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Algorithm_I_Day_12_Dynamic_Programming, Dynamic_Programming_I_Day_2, Level_1_Day_10_Dynamic_Programming, Udemy_Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 48 | 96.01
1294+
| 0064 |[Minimum Path Sum](src/main/ruby/g0001_0100/s0064_minimum_path_sum/solution.rb)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Dynamic_Programming_I_Day_16, Udemy_Dynamic_Programming, Big_O_Time_O(m\*n)_Space_O(m\*n) | 78 | 52.50
1295+
| 0062 |[Unique Paths](src/main/ruby/g0001_0100/s0062_unique_paths/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Algorithm_II_Day_13_Dynamic_Programming, Dynamic_Programming_I_Day_15, Level_1_Day_11_Dynamic_Programming, Big_O_Time_O(m\*n)_Space_O(m\*n) | 50 | 91.92
1296+
| 0056 |[Merge Intervals](src/main/ruby/g0001_0100/s0056_merge_intervals/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Data_Structure_II_Day_2_Array, Level_2_Day_17_Interval, Udemy_2D_Arrays/Matrix, Big_O_Time_O(n_log_n)_Space_O(n) | 103 | 74.70
1297+
| 0055 |[Jump Game](src/main/ruby/g0001_0100/s0055_jump_game/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Algorithm_II_Day_12_Dynamic_Programming, Dynamic_Programming_I_Day_4, Udemy_Arrays, Big_O_Time_O(n)_Space_O(1) | 88 | 95.88
1298+
| 0053 |[Maximum Subarray](src/main/ruby/g0001_0100/s0053_maximum_subarray/solution.rb)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Data_Structure_I_Day_1_Array, Dynamic_Programming_I_Day_5, Udemy_Famous_Algorithm, Big_O_Time_O(n)_Space_O(1) | 125 | 81.22
1299+
| 0051 |[N-Queens](src/main/ruby/g0001_0100/s0051_n_queens/solution.rb)| Hard | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(N!)_Space_O(N) | 82 | 88.89
1300+
| 0049 |[Group Anagrams](src/main/ruby/g0001_0100/s0049_group_anagrams/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Data_Structure_II_Day_8_String, Programming_Skills_II_Day_11, Udemy_Strings, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 154 | 83.69
1301+
| 0048 |[Rotate Image](src/main/ruby/g0001_0100/s0048_rotate_image/solution.rb)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Data_Structure_II_Day_3_Array, Programming_Skills_II_Day_7, Udemy_2D_Arrays/Matrix, Big_O_Time_O(n^2)_Space_O(1) | 50 | 93.64
12651302
| 0046 |[Permutations](src/main/ruby/g0001_0100/s0046_permutations/solution.rb)| 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!) | 62 | 89.60
12661303
| 0045 |[Jump Game II](src/main/ruby/g0001_0100/s0045_jump_game_ii/solution.rb)| 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) | 68 | 75.23
12671304
| 0042 |[Trapping Rain Water](src/main/ruby/g0001_0100/s0042_trapping_rain_water/solution.rb)| 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) | 69 | 80.74
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
48\. Rotate Image
2+
3+
Medium
4+
5+
You are given an`n x n` 2D`matrix` representing an image, rotate the image by**90** degrees (clockwise).
6+
7+
You have to rotate the image[**in-place**](https://en.wikipedia.org/wiki/In-place_algorithm), which means you have to modify the input 2D matrix directly.**DO NOT** allocate another 2D matrix and do the rotation.
8+
9+
**Example 1:**
10+
11+
![](https://assets.leetcode.com/uploads/2020/08/28/mat1.jpg)
12+
13+
**Input:** matrix =[[1,2,3],[4,5,6],[7,8,9]]
14+
15+
**Output:**[[7,4,1],[8,5,2],[9,6,3]]
16+
17+
**Example 2:**
18+
19+
![](https://assets.leetcode.com/uploads/2020/08/28/mat2.jpg)
20+
21+
**Input:** matrix =[[5,1,9,11],[2,4,8,10],[13,3,6,7],[15,14,12,16]]
22+
23+
**Output:**[[15,13,2,5],[14,3,4,1],[12,6,8,9],[16,7,10,11]]
24+
25+
**Example 3:**
26+
27+
**Input:** matrix =[[1]]
28+
29+
**Output:**[[1]]
30+
31+
**Example 4:**
32+
33+
**Input:** matrix =[[1,2],[3,4]]
34+
35+
**Output:**[[3,1],[4,2]]
36+
37+
**Constraints:**
38+
39+
*`matrix.length == n`
40+
*`matrix[i].length == n`
41+
*`1 <= n <= 20`
42+
*`-1000 <= matrix[i][j] <= 1000`
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Math #Matrix
2+
# #Data_Structure_II_Day_3_Array #Programming_Skills_II_Day_7 #Udemy_2D_Arrays/Matrix
3+
# #Big_O_Time_O(n^2)_Space_O(1) #2023_11_21_Time_50_ms_(93.64%)_Space_211_MB_(87.27%)
4+
5+
# @param {Integer[][]} matrix
6+
# @return {Void} Do not return anything, modify matrix in-place instead.
7+
defrotate(matrix)
8+
n=matrix.length
9+
(0...n /2).eachdo |i|
10+
(i...(n -i -1)).eachdo |j|
11+
pos=[[i,j],[j,n -1 -i],[n -1 -i,n -1 -j],[n -1 -j,i]]
12+
t=matrix[pos[0][0]][pos[0][1]]
13+
(1...pos.length).eachdo |k|
14+
temp=matrix[pos[k][0]][pos[k][1]]
15+
matrix[pos[k][0]][pos[k][1]]=t
16+
t=temp
17+
end
18+
matrix[pos[0][0]][pos[0][1]]=t
19+
end
20+
end
21+
end
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
49\. Group Anagrams
2+
3+
Medium
4+
5+
Given an array of strings`strs`, group**the anagrams** together. You can return the answer in**any order**.
6+
7+
An**Anagram** is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once.
8+
9+
**Example 1:**
10+
11+
**Input:** strs =["eat","tea","tan","ate","nat","bat"]
12+
13+
**Output:**[["bat"],["nat","tan"],["ate","eat","tea"]]
14+
15+
**Example 2:**
16+
17+
**Input:** strs =[""]
18+
19+
**Output:**[[""]]
20+
21+
**Example 3:**
22+
23+
**Input:** strs =["a"]
24+
25+
**Output:**[["a"]]
26+
27+
**Constraints:**
28+
29+
* <code>1 <= strs.length <= 10<sup>4</sup></code>
30+
*`0 <= strs[i].length <= 100`
31+
*`strs[i]` consists of lowercase English letters.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #String #Hash_Table #Sorting
2+
# #Data_Structure_II_Day_8_String #Programming_Skills_II_Day_11 #Udemy_Strings
3+
# #Big_O_Time_O(n*k_log_k)_Space_O(n) #2023_11_21_Time_154_ms_(83.69%)_Space_216_MB_(66.43%)
4+
5+
# @param {String[]} strs
6+
# @return {String[][]}
7+
defgroup_anagrams(strs)
8+
hm=Hash.new{|hash,key|hash[key]=[]}
9+
10+
strs.eachdo |s|
11+
sorted_str=s.chars.sort.join
12+
hm[sorted_str] <<s
13+
end
14+
15+
hm.values
16+
end
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
51\. N-Queens
2+
3+
Hard
4+
5+
The**n-queens** puzzle is the problem of placing`n` queens on an`n x n` chessboard such that no two queens attack each other.
6+
7+
Given an integer`n`, return_all distinct solutions to the**n-queens puzzle**_. You may return the answer in**any order**.
8+
9+
Each solution contains a distinct board configuration of the n-queens' placement, where`'Q'` and`'.'` both indicate a queen and an empty space, respectively.
10+
11+
**Example 1:**
12+
13+
![](https://assets.leetcode.com/uploads/2020/11/13/queens.jpg)
14+
15+
**Input:** n = 4
16+
17+
**Output:**[[".Q..","...Q","Q...","..Q."],["..Q.","Q...","...Q",".Q.."]]
18+
19+
**Explanation:** There exist two distinct solutions to the 4-queens puzzle as shown above
20+
21+
**Example 2:**
22+
23+
**Input:** n = 1
24+
25+
**Output:**[["Q"]]
26+
27+
**Constraints:**
28+
29+
*`1 <= n <= 9`

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp