FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
leetcode/code/lc36.java at master · mJackie/leetcode · GitHub
mJackie
/
leetcode
Public
Notifications
You must be signed in to change notification settings
Fork
135
Star
405
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
leetcode
/
code
/
lc36.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
28 lines (27 loc) · 980 Bytes
Breadcrumbs
leetcode
/
code
/
lc36.java
Copy path
File metadata and controls
28 lines (27 loc) · 980 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package
code
;
/*
* 36. Valid Sudoku
* 题意:横排,竖排,3*3不能包含相同数字
* 难度:Medium
* 分类:Hash Table
* 思路:用一个Set即可,把行号,列号拼上去
* Tips:注意add如果已经有了,返回的是false
*/
import
java
.
util
.
HashSet
;
public
class
lc36
{
public
boolean
isValidSudoku
(
char
[][]
board
) {
HashSet
<
String
>
hs
=
new
HashSet
();
// 如果此set已包含该元素,则该调用不更改set并返回false。
for
(
int
i
=
0
;
i
<
board
.
length
;
i
++) {
for
(
int
j
=
0
;
j
<
board
[
0
].
length
;
j
++) {
if
(
board
[
i
][
j
]==
'.'
)
continue
;
boolean
flag1
=
hs
.
add
(
board
[
i
][
j
]+
"row"
+
i
);
boolean
flag2
=
hs
.
add
(
board
[
i
][
j
]+
"col"
+
j
);
boolean
flag3
=
hs
.
add
(
board
[
i
][
j
]+
"box"
+
i
/
3
+
j
/
3
);
if
((!
flag1
)||(!
flag2
)||(!
flag3
)) {
return
false
;
}
}
}
return
true
;
}
}
Back
|
FazBrowse Home
|
New Git URL