File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 43
43
42|[ Trapping Rain Water] ( ./0042-trapping-rain-water.js ) |Hard|
44
44
43|[ Multiply Strings] ( ./0043-multiply-strings.js ) |Medium|
45
45
46|[ Permutations] ( ./0046-permutations.js ) |Medium|
46
+ 48|[ Rotate Image] ( ./0048-rotate-image.js ) |Medium|
46
47
49|[ Group Anagrams] ( ./0049-group-anagrams.js ) |Medium|
47
48
50|[ Pow(x, n)] ( ./0050-powx-n.js ) |Medium|
48
49
53|[ Maximum Subarray] ( ./0053-maximum-subarray.js ) |Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 48. Rotate Image
3
+ * https://leetcode.com/problems/rotate-image/
4
+ * Difficulty: Medium
5
+ *
6
+ * You are given an n x n 2D matrix representing an image, rotate the image by
7
+ * 90 degrees (clockwise).
8
+ *
9
+ * You have to rotate the image in-place, which means you have to modify the input
10
+ * 2D matrix directly. DO NOT allocate another 2D matrix and do the rotation.
11
+ */
12
+
13
+ /**
14
+ * @param {number[][] } matrix
15
+ * @return {void } Do not return anything, modify matrix in-place instead.
16
+ */
17
+ var rotate = function ( matrix ) {
18
+ matrix = matrix . reverse ( ) ;
19
+
20
+ for ( let i = 0 ; i < matrix . length ; i ++ ) {
21
+ for ( let j = 0 ; j < i ; j ++ ) {
22
+ [ matrix [ i ] [ j ] , matrix [ j ] [ i ] ] = [ matrix [ j ] [ i ] , matrix [ i ] [ j ] ] ;
23
+ }
24
+ }
25
+
26
+ return matrix ;
27
+ } ;
You can’t perform that action at this time.
0 commit comments