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
970ee90f
Unverified
Commit
970ee90f
authored
Jul 21, 2021
by
ASAHI OCEAN
Committed by
GitHub
Jul 21, 2021
Browse files
Merge pull request #213 from asahiocean/develop
Update Contents.swift
parents
290804a1
f1bb3d78
Changes
1
Hide whitespace changes
Inline
Side-by-side
Array/Avoid Flood in The City/avoid-flood-in-the-city.playground/Contents.swift
View file @
970ee90f
import
Foundation
// 1488. Avoid Flood in The City
// https://leetcode.com/problems/avoid-flood-in-the-city/
// Discuss: https://vk.cc/c4akh5
class
Solution
{
func
avoidFlood
(
_
rains
:
[
Int
])
->
[
Int
]
{
var
result
=
[
Int
](
repeating
:
-
1
,
count
:
rains
.
count
)
var
map
=
[
Int
:[
Int
]]()
var
dd
=
[
Int
]()
var
map
=
[
Int
:[
Int
]](),
dd
=
[
Int
]()
for
i
in
0
..<
rains
.
count
{
if
rains
[
i
]
==
0
{
dd
.
append
(
i
)
...
...
@@ -20,18 +21,16 @@ class Solution {
}
else
{
return
[]
}
for
j
in
0
..<
dd
.
count
{
if
dd
[
j
]
>
map
[
r
]
!
[
1
]
{
result
[
dd
[
j
]]
=
r
dd
.
remove
(
at
:
j
)
map
[
r
]
!
[
1
]
=
i
break
}
for
j
in
0
..<
dd
.
count
where
dd
[
j
]
>
map
[
r
]
!
[
1
]
{
result
[
dd
[
j
]]
=
r
dd
.
remove
(
at
:
j
)
map
[
r
]
!
[
1
]
=
i
break
}
}
}
}
dd
.
forEach
(
{
result
[
$0
]
=
1
}
)
dd
.
forEach
{
result
[
$0
]
=
1
}
return
result
}
}
...
...
@@ -42,19 +41,19 @@ import XCTest
class
Tests
:
XCTestCase
{
private
let
s
=
Solution
()
func
test
Example1
()
{
func
test
0
()
{
XCTAssertEqual
(
s
.
avoidFlood
([
1
,
2
,
3
,
4
]),
[
-
1
,
-
1
,
-
1
,
-
1
])
}
func
test
Example2
()
{
func
test
1
()
{
XCTAssertEqual
(
s
.
avoidFlood
([
1
,
2
,
0
,
0
,
2
,
1
]),
[
-
1
,
-
1
,
2
,
1
,
-
1
,
-
1
])
}
func
test
Example3
()
{
func
test
2
()
{
XCTAssertEqual
(
s
.
avoidFlood
([
1
,
2
,
0
,
1
,
2
]),
[])
}
func
test
Example4
()
{
func
test
3
()
{
XCTAssertEqual
(
s
.
avoidFlood
([
69
,
0
,
0
,
0
,
69
]),
[
-
1
,
69
,
1
,
1
,
-
1
])
}
func
test
Example5
()
{
func
test
4
()
{
XCTAssertEqual
(
s
.
avoidFlood
([
10
,
20
,
20
]),
[])
}
}
...
...
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