Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
yaozc
ProjectLeet
Commits
1a24a66d
Commit
1a24a66d
authored
Jan 31, 2019
by
yaozc
Browse files
36 solved
parent
19607155
Changes
1
Hide whitespace changes
Inline
Side-by-side
code.cpp
View file @
1a24a66d
...
...
@@ -99,4 +99,40 @@ int searchInsert(vector<int>& nums, int target) {
}
}
return
nums
.
size
();
}
\ No newline at end of file
}
// 36 Valid Sudoku
// an easy median problem, used set to deal with the repeated num problem
// not fast, but works
bool
isValidSudoku
(
vector
<
vector
<
char
>>&
board
)
{
vector
<
set
<
char
>
>
rows
;
vector
<
set
<
char
>
>
cols
;
vector
<
set
<
char
>
>
boxs
;
rows
.
resize
(
9
);
cols
.
resize
(
9
);
boxs
.
resize
(
9
);
for
(
int
r
=
0
;
r
<
9
;
r
++
){
for
(
int
c
=
0
;
c
<
9
;
c
++
){
if
(
board
[
r
][
c
]
!=
'.'
){
int
box_index
=
(
r
/
3
)
*
3
+
c
/
3
;
if
(
rows
[
r
].
find
((
board
[
r
][
c
]))
==
rows
[
r
].
end
()
&&
cols
[
c
].
find
((
board
[
r
][
c
]))
==
cols
[
c
].
end
()
&&
boxs
[
box_index
].
find
(
board
[
r
][
c
])
==
boxs
[
box_index
].
end
()){
rows
[
r
].
insert
(
board
[
r
][
c
]);
cols
[
c
].
insert
(
board
[
r
][
c
]);
boxs
[
box_index
].
insert
(
board
[
r
][
c
]);
}
else
{
return
false
;
}
}
}
}
return
true
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment