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 5eea853

Browse files
committed
Add solution 36.
1 parent c13b671 commit 5eea853

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
class Solution {
2+
3+
/**
4+
* @param String[][] $board
5+
* @return Boolean
6+
*/
7+
function isValidSudoku($board) {
8+
$list = [];
9+
for ($i = 0; $i < 9; $i++){
10+
for ($j = 0; $j < 9; $j++){
11+
$c = $board[$i][$j];
12+
if ($c == '.') continue;
13+
if (in_array($c, $list)) return false;
14+
$list[] = $c;
15+
}
16+
$list = [];
17+
}
18+
for ($i = 0; $i < 9; $i++){
19+
for ($j = 0; $j < 9; $j++){
20+
$c = $board[$j][$i];
21+
if ($c == '.') continue;
22+
if (in_array($c, $list)) return false;
23+
$list[] = $c;
24+
}
25+
$list = [];
26+
}
27+
for ($i = 0; $i < 3; $i++){
28+
for ($j = 0; $j < 3; $j++){
29+
for ($x = 3*$i; $x < 3+3*$i; $x++){
30+
for ($y = 3*$j; $y < 3+3*$j; $y++){
31+
$c = $board[$x][$y];
32+
if ($c == '.') continue;
33+
if (in_array($c, $list)) return false;
34+
$list[] = $c;
35+
}
36+
}
37+
$list = [];
38+
}
39+
}
40+
return true;
41+
}
42+
}

0 commit comments

Comments
(0)

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