Movatterモバイル変換


[0]ホーム

URL:


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

Commitdff6ce2

Browse files
committed
Time: 3 ms (91.93%), Space: 48.9 MB (42.67%) - LeetHub
1 parentb376782 commitdff6ce2

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
classSolution {
2+
privatefun BooleanArray.clear() {
3+
for (iin indices) {
4+
this[i]=false
5+
}
6+
}
7+
8+
funisValidSudoku(board:Array<CharArray>):Boolean {
9+
val isFilled=BooleanArray(10)
10+
11+
for (rowin board) {
12+
isFilled.clear()
13+
14+
for (charin row) {
15+
if (char=='.') {
16+
continue
17+
}
18+
19+
val number= char.digitToInt()
20+
if (isFilled[number]) {
21+
returnfalse
22+
}
23+
isFilled[number]=true
24+
}
25+
}
26+
27+
for (xin0 until9) {
28+
isFilled.clear()
29+
30+
for (yin0 until9) {
31+
val char= board[y][x]
32+
33+
if (char=='.') {
34+
continue
35+
}
36+
37+
val number= char.digitToInt()
38+
if (isFilled[number]) {
39+
returnfalse
40+
}
41+
isFilled[number]=true
42+
}
43+
}
44+
45+
for (gridYin0 until3) {
46+
for (gridXin0 until3) {
47+
isFilled.clear()
48+
49+
val startY= gridY*3
50+
val startX= gridX*3
51+
for (yin startY until startY+3) {
52+
for (xin startX until startX+3) {
53+
val char= board[y][x]
54+
55+
if (char=='.') {
56+
continue
57+
}
58+
59+
val number= char.digitToInt()
60+
if (isFilled[number]) {
61+
returnfalse
62+
}
63+
isFilled[number]=true
64+
}
65+
}
66+
}
67+
}
68+
69+
returntrue
70+
}
71+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp