Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
asahiocean
LeetCode
Commits
f3a8602a
Unverified
Commit
f3a8602a
authored
Jul 21, 2021
by
ASAHI OCEAN
Committed by
GitHub
Jul 21, 2021
Browse files
Merge pull request #208 from asahiocean/develop
36. Valid Sudoku
parents
6cb56854
fa28ddb8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Array/.DS_Store
View file @
f3a8602a
No preview for this file type
Array/Valid Sudoku/valid-sudoku.playground/Contents.swift
0 → 100644
View file @
f3a8602a
import
Foundation
// 36. Valid Sudoku
// https://leetcode.com/problems/valid-sudoku/
class
Solution
{
func
isValidSudoku
(
_
board
:
[[
Character
]])
->
Bool
{
for
index
in
board
.
indices
{
let
row
=
board
[
index
]
.
filter
{
$0
!=
"."
}
if
row
.
count
!=
Set
(
row
)
.
count
{
return
false
}
let
col
=
board
.
map
{
$0
[
index
]
}
.
filter
{
$0
!=
"."
}
if
col
.
count
!=
Set
(
col
)
.
count
{
return
false
}
let
n
=
(
i
:
3
*
(
index
/
3
),
j
:
3
*
(
index
%
3
))
let
blocks
=
board
[
n
.
i
..<
n
.
i
+
3
]
.
flatMap
{
$0
[
n
.
j
..<
n
.
j
+
3
]}
.
filter
{
$0
!=
"."
}
if
blocks
.
count
!=
Set
(
blocks
)
.
count
{
return
false
}
}
return
true
}
}
import
XCTest
// Executed 2 tests, with 0 failures (0 unexpected) in 0.173 (0.175) seconds
class
Tests
:
XCTestCase
{
private
let
s
=
Solution
()
func
test0
()
{
let
res
=
s
.
isValidSudoku
([[
"5"
,
"3"
,
"."
,
"."
,
"7"
,
"."
,
"."
,
"."
,
"."
],[
"6"
,
"."
,
"."
,
"1"
,
"9"
,
"5"
,
"."
,
"."
,
"."
],[
"."
,
"9"
,
"8"
,
"."
,
"."
,
"."
,
"."
,
"6"
,
"."
],[
"8"
,
"."
,
"."
,
"."
,
"6"
,
"."
,
"."
,
"."
,
"3"
],[
"4"
,
"."
,
"."
,
"8"
,
"."
,
"3"
,
"."
,
"."
,
"1"
],[
"7"
,
"."
,
"."
,
"."
,
"2"
,
"."
,
"."
,
"."
,
"6"
],[
"."
,
"6"
,
"."
,
"."
,
"."
,
"."
,
"2"
,
"8"
,
"."
],[
"."
,
"."
,
"."
,
"4"
,
"1"
,
"9"
,
"."
,
"."
,
"5"
],[
"."
,
"."
,
"."
,
"."
,
"8"
,
"."
,
"."
,
"7"
,
"9"
]])
XCTAssertEqual
(
res
,
true
)
}
func
test1
()
{
let
res
=
s
.
isValidSudoku
([[
"8"
,
"3"
,
"."
,
"."
,
"7"
,
"."
,
"."
,
"."
,
"."
],[
"6"
,
"."
,
"."
,
"1"
,
"9"
,
"5"
,
"."
,
"."
,
"."
],[
"."
,
"9"
,
"8"
,
"."
,
"."
,
"."
,
"."
,
"6"
,
"."
],[
"8"
,
"."
,
"."
,
"."
,
"6"
,
"."
,
"."
,
"."
,
"3"
],[
"4"
,
"."
,
"."
,
"8"
,
"."
,
"3"
,
"."
,
"."
,
"1"
],[
"7"
,
"."
,
"."
,
"."
,
"2"
,
"."
,
"."
,
"."
,
"6"
],[
"."
,
"6"
,
"."
,
"."
,
"."
,
"."
,
"2"
,
"8"
,
"."
],[
"."
,
"."
,
"."
,
"4"
,
"1"
,
"9"
,
"."
,
"."
,
"5"
],[
"."
,
"."
,
"."
,
"."
,
"8"
,
"."
,
"."
,
"7"
,
"9"
]])
XCTAssertEqual
(
res
,
false
)
}
}
Tests
.
defaultTestSuite
.
run
()
Array/Valid Sudoku/valid-sudoku.playground/contents.xcplayground
0 → 100644
View file @
f3a8602a
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground
version=
'5.0'
target-platform=
'ios'
>
<timeline
fileName=
'timeline.xctimeline'
/>
</playground>
\ No newline at end of file
Write
Preview
Supports
Markdown
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