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 bf8fad8

Browse files
committed
Add solution 48.
1 parent d02ceeb commit bf8fad8

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class Solution {
2+
3+
/**
4+
* @param Integer[][] $matrix
5+
* @return NULL
6+
*/
7+
function rotate(&$matrix) {
8+
for ($i = 0; $i < count($matrix); $i++) {
9+
for ($j = $i; $j < count($matrix); $j++) {
10+
if ($i == $j) continue;
11+
$temp = $matrix[$i][$j];
12+
$matrix[$i][$j] = $matrix[$j][$i];
13+
$matrix[$j][$i] = $temp;
14+
}
15+
}
16+
for ($i = 0; $i < count($matrix); $i++) {
17+
$start = 0;
18+
$end = count($matrix[$i]) - 1;
19+
while ($start < $end) {
20+
$temp = $matrix[$i][$start];
21+
$matrix[$i][$start] = $matrix[$i][$end];
22+
$matrix[$i][$end] = $temp;
23+
$start++;
24+
$end--;
25+
}
26+
}
27+
}
28+
}

0 commit comments

Comments
(0)

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