8000 Added tasks 48-72 · pytdev/LeetCode-in-Php@69de6cb · GitHub
[go: up one dir, main page]

Skip to content

Commit 69de6cb

Browse files
authored
Added tasks 48-72
1 parent 133cf0c commit 69de6cb

File tree

31 files changed

+935
-0
lines changed

31 files changed

+935
-0
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated.
204204

205205
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
206206
|-|-|-|-|-|-
207+
| 0070 |[Climbing Stairs](src/main/php/g0001_0100/s0070_climbing_stairs/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 3 | 82.81
207208

208209
#### Day 3
209210

@@ -214,12 +215,14 @@ Php-based LeetCode algorithm problem solutions, regularly updated.
214215

215216
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
216217
|-|-|-|-|-|-
218+
| 0055 |[Jump Game](src/main/php/g0001_0100/s0055_jump_game/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 129 | 74.56
217219
| 0045 |[Jump Game II](src/main/php/g0001_0100/s0045_jump_game_ii/Solution.php)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 31 | 63.46
218220

219221
#### Day 5
220222

221223
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
222224
|-|-|-|-|-|-
225+
| 0053 |[Maximum Subarray](src/main/php/g0001_0100/s0053_maximum_subarray/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 185 | 95.51
223226

224227
#### Day 6
225228

@@ -271,11 +274,13 @@ Php-based LeetCode algorithm problem solutions, regularly updated.
271274

272275
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
273276
|-|-|-|-|-|-
277+
| 0062 |[Unique Paths](src/main/php/g0001_0100/s0062_unique_paths/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 3 | 81.58
274278

275279
#### Day 16
276280

277281
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
278282
|-|-|-|-|-|-
283+
| 0064 |[Minimum Path Sum](src/main/php/g0001_0100/s0064_minimum_path_sum/Solution.php)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 20 | 81.48
279284

280285
#### Day 17
281286

@@ -292,6 +297,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated.
292297

293298
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
294299
|-|-|-|-|-|-
300+
| 0072 |[Edit Distance](src/main/php/g0001_0100/s0072_edit_distance/Solution.php)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 29 | 75.00
295301

296302
#### Day 20
297303

@@ -401,6 +407,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated.
401407

402408
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
403409
|-|-|-|-|-|-
410+
| 0048 |[Rotate Image](src/main/php/g0001_0100/s0048_rotate_image/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 4 | 81.58
404411

405412
#### Day 8
406413

@@ -421,6 +428,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated.
421428

422429
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
423430
|-|-|-|-|-|-
431+
| 0049 |[Group Anagrams](src/main/php/g0001_0100/s0049_group_anagrams/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 27 | 80.85
424432

425433
#### Day 12
426434

@@ -644,11 +652,13 @@ Php-based LeetCode algorithm problem solutions, regularly updated.
644652

645653
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
646654
|-|-|-|-|-|-
655+
| 0070 |[Climbing Stairs](src/main/php/g0001_0100/s0070_climbing_stairs/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 3 | 82.81
647656

648657
#### Day 11 Dynamic Programming
649658

650659
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
651660
|-|-|-|-|-|-
661+
| 0062 |[Unique Paths](src/main/php/g0001_0100/s0062_unique_paths/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 3 | 81.58
652662

653663
#### Day 12 Sliding Window/Two Pointer
654664

@@ -760,6 +770,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated.
760770

761771
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
762772
|-|-|-|-|-|-
773+
| 0056 |[Merge Intervals](src/main/php/g0001_0100/s0056_merge_intervals/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 48 | 80.00
763774

764775
#### Day 18 Stack
765776

@@ -794,6 +805,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated.
794805
| 0003 |[Longest Substring Without Repeating Characters](src/main/php/g0001_0100/s0003_longest_substring_without_repeating_characters/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Hash_Table, Sliding_Window, Big_O_Time_O(n)_Space_O(1) | 4 | 99.33
795806
| 0020 |[Valid Parentheses](src/main/php/g0001_0100/s0020_valid_parentheses/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, String, Stack, Big_O_Time_O(n)_Space_O(n) | 3 | 88.14
796807
| 0005 |[Longest Palindromic Substring](src/main/php/g0001_0100/s0005_longest_palindromic_substring/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Big_O_Time_O(n)_Space_O(n) | 13 | 98.57
808+
| 0049 |[Group Anagrams](src/main/php/g0001_0100/s0049_group_anagrams/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 27 | 80.85
797809

798810
#### Udemy Binary Search
799811

@@ -806,6 +818,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated.
806818
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
807819
|-|-|-|-|-|-
808820
| 0001 |[Two Sum](src/main/php/g0001_0100/s0001_two_sum/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 9 | 97.47
821+
| 0055 |[Jump Game](src/main/php/g0001_0100/s0055_jump_game/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 129 | 74.56
809822
| 0041 |[First Missing Positive](src/main/php/g0001_0100/s0041_first_missing_positive/Solution.php)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, Array, Hash_Table, Big_O_Time_O(n)_Space_O(n) | 111 | 90.48
810823

811824
#### Udemy Two Pointers
@@ -819,6 +832,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated.
819832

820833
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
821834
|-|-|-|-|-|-
835+
| 0053 |[Maximum Subarray](src/main/php/g0001_0100/s0053_maximum_subarray/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 185 | 95.51
822836

823837
#### Udemy Sorting Algorithms
824838

@@ -829,6 +843,8 @@ Php-based LeetCode algorithm problem solutions, regularly updated.
829843

830844
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
831845
|-|-|-|-|-|-
846+
| 0048 |[Rotate Image](src/main/php/g0001_0100/s0048_rotate_image/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 4 | 81.58
847+
| 0056 |[Merge Intervals](src/main/php/g0001_0100/s0056_merge_intervals/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 48 | 80.00
832848

833849
#### Udemy Linked List
834850

@@ -857,6 +873,9 @@ Php-based LeetCode algorithm problem solutions, regularly updated.
857873

858874
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
859875
|-|-|-|-|-|-
876+
| 0070 |[Climbing Stairs](src/main/php/g0001_0100/s0070_climbing_stairs/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 3 | 82.81
877+
| 0064 |[Minimum Path Sum](src/main/php/g0001_0100/s0064_minimum_path_sum/Solution.php)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Matrix, Big_O_Time_O(m\*n)_Space_O(m\*n) | 20 | 81.48
878+
| 0072 |[Edit Distance](src/main/php/g0001_0100/s0072_edit_distance/Solution.php)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 29 | 75.00
860879
| 0010 |[Regular Expression Matching](src/main/php/g0001_0100/s0010_regular_expression_matching/Solution.php)| Hard | Top_100_Liked_Questions, Top_Interview_Questions, String, Dynamic_Programming, Recursion, Big_O_Time_O(m\*n)_Space_O(m\*n) | 10 | 64.52
861880

862881
#### Udemy Backtracking/Recursion
@@ -884,6 +903,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated.
884903

885904
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
886905
|-|-|-|-|-|-
906+
| 0053 |[Maximum Subarray](src/main/php/g0001_0100/s0053_maximum_subarray/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Divide_and_Conquer, Big_O_Time_O(n)_Space_O(1) | 185 | 95.51
887907

888908
#### Day 2 Array
889909

@@ -965,11 +985,13 @@ Php-based LeetCode algorithm problem solutions, regularly updated.
965985

966986
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
967987
|-|-|-|-|-|-
988+
| 0056 |[Merge Intervals](src/main/php/g0001_0100/s0056_merge_intervals/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Sorting, Big_O_Time_O(n_log_n)_Space_O(n) | 48 | 80.00
968989

969990
#### Day 3 Array
970991

971992
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
972993
|-|-|-|-|-|-
994+
| 0048 |[Rotate Image](src/main/php/g0001_0100/s0048_rotate_image/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Math, Matrix, Big_O_Time_O(n^2)_Space_O(1) | 4 | 81.58
973995

974996
#### Day 4 Array
975997

@@ -995,6 +1017,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated.
9951017

9961018
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
9971019
|-|-|-|-|-|-
1020+
| 0049 |[Group Anagrams](src/main/php/g0001_0100/s0049_group_anagrams/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, String, Hash_Table, Sorting, Big_O_Time_O(n\*k_log_k)_Space_O(n) | 27 | 80.85
9981021

9991022
#### Day 9 String
10001023

@@ -1131,6 +1154,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated.
11311154

11321155
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
11331156
|-|-|-|-|-|-
1157+
| 0070 |[Climbing Stairs](src/main/php/g0001_0100/s0070_climbing_stairs/Solution.php)| Easy | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Memoization, Big_O_Time_O(n)_Space_O(n) | 3 | 82.81
11341158

11351159
#### Day 13 Bit Manipulation
11361160

@@ -1210,12 +1234,14 @@ Php-based LeetCode algorithm problem solutions, regularly updated.
12101234

12111235
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
12121236
|-|-|-|-|-|-
1237+
| 0055 |[Jump Game](src/main/php/g0001_0100/s0055_jump_game/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 129 | 74.56
12131238

12141239
#### Day 13 Dynamic Programming
12151240

12161241
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
12171242
|-|-|-|-|-|-
12181243
| 0045 |[Jump Game II](src/main/php/g0001_0100/s0045_jump_game_ii/Solution.php)| Medium | Top_100_Liked_Questions, Array, Dynamic_Programming, Greedy, Big_O_Time_O(n)_Space_O(1) | 31 | 63.46
1244+
| 0062 |[Unique Paths](src/main/php/g0001_0100/s0062_unique_paths/Solution.php)| Medium | Top_100_Liked_Questions, Top_Interview_Questions, Dynamic_Programming, Math, Combinatorics, Big_O_Time_O(m\*n)_Space_O(m\*n) | 3 | 81.58
12191245

12201246
#### Day 14 Dynamic Programming
12211247

@@ -1242,6 +1268,7 @@ Php-based LeetCode algorithm problem solutions, regularly updated.
12421268

12431269
| <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- --> | <!-- -->
12441270
|-|-|-|-|-|-
1271+
| 0072 |[Edit Distance](src/main/php/g0001_0100/s0072_edit_distance/Solution.php)| Hard | Top_100_Liked_Questions, String, Dynamic_Programming, Big_O_Time_O(n^2)_Space_O(n2) | 29 | 75.00
12451272

12461273
#### Day 19 Bit Manipulation
12471274

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

12631290
| # | Title | Difficulty | Tag | Time, ms | Time, %
12641291
|------|----------------|-------------|-------------|----------|---------
1292+
| 0072 |[Edit Distance](src/main/php/g0001_0100/s0072_edit_distance/Solution.php)| 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) | 29 | 75.00
1293+
| 0070 |[Climbing Stairs](src/main/php/g0001_0100/s0070_climbing_stairs/Solution.php)| 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) | 3 | 82.81
1294+
| 0064 |[Minimum Path Sum](src/main/php/g0001_0100/s0064_minimum_path_sum/Solution.php)| 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) | 20 | 81.48
1295+
| 0062 |[Unique Paths](src/main/php/g0001_0100/s0062_unique_paths/Solution.php)| 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) | 3 | 81.58
1296+
| 0056 |[Merge Intervals](src/main/php/g0001_0100/s0056_merge_intervals/Solution.php)| 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) | 48 | 80.00
1297+
| 0055 |[Jump Game](src/main/php/g0001_0100/s0055_jump_game/Solution.php)| 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) | 129 | 74.56
1298+
| 0053 |[Maximum Subarray](src/main/php/g0001_0100/s0053_maximum_subarray/Solution.php)| 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) | 185 | 95.51
1299+
| 0051 |[N-Queens](src/main/php/g0001_0100/s0051_n_queens/Solution.php)| Hard | Top_100_Liked_Questions, Array, Backtracking, Big_O_Time_O(N!)_Space_O(N) | 13 | 92.31
1300+
| 0049 |[Group Anagrams](src/main/php/g0001_0100/s0049_group_anagrams/Solution.php)| 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) | 27 | 80.85
1301+
| 0048 |[Rotate Image](src/main/php/g0001_0100/s0048_rotate_image/Solution.php)| 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) | 4 | 81.58
12651302
| 0046 |[Permutations](src/main/php/g0001_0100/s0046_permutations/Solution.php)| 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!) | 4 | 92.42
12661303
| 0045 |[Jump Game II](src/main/php/g0001_0100/s0045_jump_game_ii/Solution.php)| 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) | 31 | 63.46
12671304
| 0042 |[Trapping Rain Water](src/main/php/g0001_0100/s0042_trapping_rain_water/Solution.php)| 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) | 29 | 69.15
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace leetcode\g0001_0100\s0048_rotate_image;
4< 10000 /code>+
5+
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #Math #Matrix
6+
// #Data_Structure_II_Day_3_Array #Programming_Skills_II_Day_7 #Udemy_2D_Arrays/Matrix
7+
// #Big_O_Time_O(n^2)_Space_O(1) #2023_12_10_Time_4_ms_(81.58%)_Space_19.4_MB_(10.53%)
8+
9+
class Solution {
10+
/**
11+
* @param Integer[][] $matrix
12+
* @return NULL
13+
*/
14+
public function rotate(&$matrix) {
15+
$n = count($matrix);
16+
for ($i = 0; $i < $n / 2; $i++) {
17+
for ($j = $i; $j < $n - $i - 1; $j++) {
18+
$pos = array(
19+
array($i, $j),
20+
array($j, $n - 1 - $i),
21+
array($n - 1 - $i, $n - 1 - $j),
22+
array($n - 1 - $j, $i)
23+
);
24+
$t = $matrix[$pos[0][0]][$pos[0][1]];
25+
for ($k = 1; $k < count($pos); $k++) {
26+
$temp = $matrix[$pos[$k][0]][$pos[$k][1]];
27+
$matrix[$pos[$k][0]][$pos[$k][1]] = $t;
28+
$t = $temp;
29+
}
30+
$matrix[$pos[0][0]][$pos[0][1]] = $t;
31+
}
32+
}
33+
}
34+
}
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: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace leetcode\g0001_0100\s0049_group_anagrams;
4+
5+
// #Medium #Top_100_Liked_Questions #Top_Interview_Questions #Array #String #Hash_Table #Sorting
6+
// #Data_Structure_II_Day_8_String #Programming_Skills_II_Day_11 #Udemy_Strings
7+
// #Big_O_Time_O(n*k_log_k)_Space_O(n) #2023_12_10_Time_27_ms_(80.85%)_Space_25.8_MB_(27.66%)
8+
9+
class Solution {
10+
/**
11+
* @param String[] $strs
12+
* @return String[][]
13+
*/
14+
public function groupAnagrams($strs) {
15+
$hm = array();
16+
foreach ($strs as $s) {
17+
$ch = str_split($s);
18+
sort($ch);
19+
$temp = implode($ch);
20+
if (!array_key_exists($temp, $hm)) {
21+
$hm[$temp] = array();
22+
}
23+
array_push($hm[$temp], $s);
24+
}
25+
return array_values($hm);
26+
}
27+
}
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.

0 commit comments

Comments
 (0)
0