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

Commit 65827f5

Browse files
feat: add javascript solution to lcci problem: No.01.07.Rotate Matrix (doocs#374)
* feat: add javascript solution to lcci problem: No.02.01.Remove Duplicate Node * feat: add javascript solution to lcci problem: No.02.02.Kth Node From End of List * feat: add javascript solution to lcci problem: No.02.03.Delete Middle Node * feat: add javascript solution to lcci problem: No.17.04.Missing Number * feat: add javascript solution to lcci problem: No.17.10.Find Majority Element * feat: add javascript solution to lcci problem: No.01.08.Zero Matrix * chore: add development environment start script * feat: add javascript solution to lcci problem: No.01.07.Rotate Matrix
1 parent c8afc1b commit 65827f5

File tree

3 files changed

+58
-0
lines changed

3 files changed

+58
-0
lines changed

‎lcci/01.07.Rotate Matrix/README.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,27 @@ class Solution {
9797
}
9898
```
9999

100+
### **JavaScript**
101+
102+
```js
103+
/**
104+
* @param {number[][]} matrix
105+
* @return {void} Do not return anything, modify matrix in-place instead.
106+
*/
107+
var rotate = function(matrix) {
108+
const n = matrix.length;
109+
for (let i = 0; i < (n / 2); i++) {
110+
for (let j = i; j < n - i - 1; j++) {
111+
let t = matrix[i][j];
112+
matrix[i][j] = matrix[n - j - 1][i];
113+
matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1];
114+
matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1];
115+
matrix[j][n - i - 1] = t;
116+
}
117+
}
118+
};
119+
```
120+
100121
### **...**
101122

102123
```

‎lcci/01.07.Rotate Matrix/README_EN.md‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,27 @@ class Solution {
118118
}
119119
```
120120

121+
### **JavaScript**
122+
123+
```js
124+
/**
125+
* @param {number[][]} matrix
126+
* @return {void} Do not return anything, modify matrix in-place instead.
127+
*/
128+
var rotate = function(matrix) {
129+
const n = matrix.length;
130+
for (let i = 0; i < (n / 2); i++) {
131+
for (let j = i; j < n - i - 1; j++) {
132+
let t = matrix[i][j];
133+
matrix[i][j] = matrix[n - j - 1][i];
134+
matrix[n - j - 1][i] = matrix[n - i - 1][n - j - 1];
135+
matrix[n - i - 1][n - j - 1] = matrix[j][n - i - 1];
136+
matrix[j][n - i - 1] = t;
137+
}
138+
}
139+
};
140+
```
141+
121142
### **...**
122143

123144
```

‎lcci/01.07.Rotate Matrix/Solution.js‎

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

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /