Skip to content

Commit 84c0505

Browse files
author
zhangzhengxian
committed
7.13
1 parent 8f38706 commit 84c0505

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
|43|[Multiply Strings](https://leetcode.com/problems/multiply-strings/)| [JavaScript](./algorithms/Multiply_Strings.js)|Medium|
4040
|46|[Permutations](https://leetcode.com/problems/permutations/)| [JavaScript](./algorithms/Permutations.js)|Medium|
4141
|47|[Permutations II](https://leetcode.com/problems/permutations-ii/)| [JavaScript](./algorithms/PermutationsII.js)|Medium|
42+
|48|[Rotate Image](https://leetcode.com/problems/permutations-ii/)| [JavaScript](./algorithms/ RotateImage.js)|Medium|
4243
|69|[Sqrt(x)](https://leetcode.com/problems/sqrtx/)| [JavaScript](./algorithms/Sqrt(x).js)|Easy|
4344
|371|[Sum of Two Integers](https://leetcode.com/problems/sum-of-two-integers/)| [JavaScript](./algorithms/Sum_of_Two_Integers.js)|Easy|
4445
|372|[Super Pow](https://leetcode.com/problems/super-pow/)| [JavaScript](./algorithms/SuperPow.js)|Medium|

algorithms/RotateImage.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* @param {number[][]} matrix
3+
* @return {void} Do not return anything, modify matrix in-place instead.
4+
*/
5+
var rotate = function(matrix) {
6+
var l = matrix.length,
7+
temp = [];
8+
for (var i = 0; i < Math.floor(l / 2); i++){
9+
for(var j = i; j < l - i - 1; j++) {
10+
temp = [matrix[i][j], matrix[j][l - i - 1], matrix[l - i - 1][l - j - 1], matrix[l - j - 1][i]];
11+
matrix[i][j] = temp[3];
12+
matrix[j][l - i - 1] = temp[0];
13+
matrix[l - i - 1][l - j - 1] = temp[1];
14+
matrix[l - j -1][i] = temp[2];
15+
}
16+
}
17+
};

0 commit comments

Comments
 (0)