-
Notifications
You must be signed in to change notification settings - Fork 0
3 - Bishoe01 #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3 - Bishoe01 #16
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํ์ด ๋ฌธ์ ๋ฅผ ์ ๋๋ก ์ฝ์ผ๋ผ๋ ํํธ๋ฅผ ์คฌ๊ธฐ๋๋ฌธ์ ์ด๋ ต์ง์๊ฒ ํ ์ ์์์ต๋๋ค.
(๋ฌธ์ ๊ทธ๋ฆผ๋ง ๋ณด๋ฉด ๋น์ฐํ ์ธ์ ํ ์ปดํจํฐ๋ง ์๋ฒ ์ฐ๊ฒฐ ๋ ๊ฒ์ฒ๋ผ ๋ณด์;;)
์
๋ ฅ๋ grid์ ํ, ๋ ฌ์ ์์นํ ์๋ฒ ๊ฐ์๋ง ์ธ์ฃผ๋ฉด ๋ฉ๋๋ค.
์๋ํ๋ฉด '์ธ์ 'ํ ์๋ฒ๊ฐ ์๋๊ธฐ์ ๊ฐ์ ์์น์ 2๊ฐ ์ด์ ์์ผ๋ฉด ๊ฑ๋ค๋ ์ฐ๊ฒฐ๋๊ฑฐ๋๊น์.
(ํ๊ธฐํ๋ฉด์ ํ๋๋ฐ ๋๋ฌด ์ง์ ๋ถํด์ ์๊ฐ ๋ค์ฌ ์ฌ๊ธฐ์ ์จ๋ด ๋๋ค.)
์ผ๋จ ์๋ grid๋ฅผ ์์๋ก ๋ณผ๊ฒ์.
1 1 0 0
0 0 1 0
0 0 1 0
0 0 0 1
ํ์ ๊ธฐ์ค์ผ๋ก ๋ด๋ณผ๊ฒ์ฌ
[1]--[1] [ ] [ ] (ํ์ ์๋ฒ 2๊ฐ: ํต์ ๊ฐ๋ฅ)
[ ] [ ] [1] [ ] (ํ์ ์๋ฒ 1๊ฐ: X)
[ ] [ ] [1] [ ] (ํ์ ์๋ฒ 1๊ฐ: X)
[ ] [ ] [ ] [1] (ํ์ ์๋ฒ 1๊ฐ: X)
๊ฐ ์๋ฒ๊ฐ ์์นํ ํ์ ๋ค๋ฅธ ์๋ฒ๊ฐ 1๊ฐ๋ง ์์ผ๋ฉด ๊ทธ ์๋ฒ๋ ์ฐ๊ฒฐ๋ ์๋ฒ๊ฒ ์ฃ ??
์ด์ ๊ธฐ์ค์ผ๋ก๋ ํ๋ฒ ๋ด๋ณด์ ์๋.
[1] [1] [ ] [ ]
[ ] [ ] [1] [ ]
|
[ ] [ ] [1] [ ]
[ ] [ ] [ ] [1]
3(์ปดํฐ๊ธฐ์ค2)์ด๋ง ์๋ฒ 2๊ฐ๊ณ ์๋ค๋ง ์ฐ๊ฒฐ ๊ฐ๋ฅํฉ๋๋ค.
์ด๋ก์จ ์ ์ ์๋ ์ฌ์ค
๊ฐ ์๋ฒ๊ฐ ์์นํ ํ์ ๋ค๋ฅธ ์๋ฒ๊ฐ ์์ ํฌํจ 2๊ฐ๋ง ์์ผ๋ฉด ๊ทธ ์๋ฒ๋ ์ฐ๊ฒฐ๋ ์๋ฒ๋ค.
๊ฐ ์๋ฒ๊ฐ ์์นํ ์ด์ ๋ค๋ฅธ ์๋ฒ๊ฐ ์์ ํฌํจ 2๊ฐ๋ง ์์ผ๋ฉด ๊ทธ ์๋ฒ๋ ์ฐ๊ฒฐ๋ ์๋ฒ๋ค.
= ๊ฐ ์๋ฒ์ ํor์ด์ ์๋ฒ๊ฐ ์์ ํฌํจ 2๊ฐ ์ด์์ด๋ฉด ๊ทธ ์๋ฒ๋ ์ฐ๊ฒฐ๋ ์๋ฒ๋ค.
๊ทธ๋ฆฌ๊ณ ์ฐ๋ฆฐ ์ฐ๊ฒฐ๋ ์๋ฒ๋ฅผ ์ธ์ด์ฃผ๋ฉด ๋ฉ๋๋ค.
๋ฌด์์ฝ๋
์ ํ ์๋ฒ ๊ฐ์, ์ด ์๋ฒ ๊ฐ์๋ฅผ ๋ฐ๋ก ์ ์ธํด์ ํ๋๋ฐ ๋ ๋์ ๋ฐฉ๋ฒ์ด ์์์ง ๊ถ๊ธํ๋ค์
class Solution {
func countServers(_ grid: [[Int]]) -> Int {
let rows = grid.count
let cols = grid[0].count
var rowServer = Array(repeating: 0, count: rows)
var colServer = Array(repeating: 0, count: cols)
// ๊ฐ ํ, ์ด ์๋ฒ ์ ์ฑ์๋ฃ๊ธฐ
for i in 0..<rows {
for j in 0..<cols {
if grid[i][j] == 1 {
rowServer[i] += 1
colServer[j] += 1
}
}
}
// ์ํํ๋ฉด์ ์๋ฒ๊ฐ ์๋ ๊ฒฝ์ฐ, ํ or ์ด์ ์นด์ดํธ๊ฐ 2 ์ด์์ธ์ง ์ฒดํฌํ๊ณ ๋ง์ผ๋ฉด +1
var res = 0
for i in 0..<rows {
for j in 0..<cols {
if grid[i][j] == 1 && (rowServer[i] > 1 || colServer[j] > 1) {
res += 1
}
}
}
return res
}
}|
์ ๋ ๊ฐ์ ํ๊ณผ ์ด์ 1๋ ์ด์ ์์ด์ผ ํต์ ์ด ๊ฐ๋ฅํ๋ค๋ ๊ฑธ ์ธ์งํ๋๋ฐ ์ ๊ธฐ ๋งํฌ ์์์๋ C++ ์ฝ๋๋ก ์์ฑ๋์ด ์๋๋ฐ ์ค์ํํธ๋ก ๋ฐ๊ฟ๋ณด์์ต๋๋ค class Solution {
func countServers(_ grid: [[Int]]) -> Int {
let n = grid.count
let m = grid[0].count
var answer = 0
var rows = [Int](repeating: 0, count: n)
var cols = [Int](repeating: 0, count: m)
// ๊ฐ ํ๊ณผ ์ด์ ์๋ฒ ๊ฐ์๋ฅผ ์ผ๋ค
for i in 0..<n {
for j in 0..<m {
if grid[i][j] == 1 {
rows[i] += 1
cols[j] += 1
}
}
}
// ํต์ ๊ฐ๋ฅํ ์๋ฒ๋ง ์นด์ดํธํ๋ค
for i in 0..<n {
for j in 0..<m {
if grid[i][j] == 1 && (rows[i] > 1 || cols[j] > 1) {
answer += 1
}
}
}
return answer
}
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์บฌ ~ finn ์ค์ BFS ์ฝ๋๋ฅผ ๋ณด๊ณ ํํ๋ฒ ๊ตฌํํด๋ณด๊ณ ์ถ๋ค๋ ์๊ตฌ๊ฐ ๋ง ์์๋๋ค์ !!! ๋ฌด๋ฆ์ ํ ์น๊ณ ๊ฐ๋๋ค !
| // ์ด ๊ณ์ผ | ||
| for col in 0 ..< grid[0].count { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ใ ใ ์ด ๊ณ์ผ ~ finn ์ฝ๋ ์ปจํธ๋ฆฌ๋ทฐํฐ ์ฃผ์๋์ฉ ? ใ ใ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@YooGyeongMo zใ ใ ใ ใ ใ ใ ์๋ ๋ค๋ฅธ๋ถ๋ค ์ฝ๋๋ณด๋ค๊ฐ ํ์ํฐ์ก๋ค์ ใ ใ ใ ์
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ต์ฅํ ๋ถ๋๋ฝ๋ค์
| while pointer < queue.count { | ||
| let tmp = queue[pointer] | ||
| let currentX = tmp.0, currentY = tmp.1 | ||
|
|
||
| // ๊ตด๋ฌ๊ฐ ์ ์๋์ง ํ์ธ / 2์ฐจ ํ์ด : ์ฌ์ค์ ์ด๋ถ๋ถ๋ง ๊ณ ์ณ์ฃผ๋ฉด ๋ ๊ฒ๊ฐ์๋ฐ, ํ - ์ด์ด๋ผ | ||
|
|
||
| // ํ ๊ณ์ฐ | ||
| for row in 0 ..< grid.count { | ||
| // print("next:", nextX, nextY) | ||
| if isRange(x: row, y: currentY) { | ||
| // print("Hi") | ||
| queue.append((row, currentY)) | ||
| visitedGraph[row][currentY] = true | ||
| connectCnt += 1 | ||
| // print("ROW", row, currentY) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ก๊ทธ ์ฐ์ด๋ณด์๋๊ฒ ์ ๋ง ๋๋จํ๊ฑฐ๊ฐ์ต๋๋ค! finn !!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ฒ๋ค๊ฐ ์ง์ ํ๋ฅผ ๊ตฌํ ํ์ จ๊ตฐ์. ์์ฒญ ํ๋์ จ์ํ ๋ฐ..tmp.0 tmp.1๋ก ์ ๊ทผํ์ จ๋ค์ !!!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์์ BFS/DFSํ ๋ ํจ๋์ ์๋์ด pointer๋ก ํ๊ฐ ๋๋ ๊ฒ์ฒ๋ผํ์๊ธธ๋ ๊ณ์ ์ ์จ๋จน๊ณ ์์ต๋๋ค ใ ใ ..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํ ์ ์ง ๋ญ๊ฐ ์ต์ํ๋ค ์ถ์๋๋ฐ ๊ทธ๋ ์๊ฐ์ ๋ฐ์์ ์์ฐ๊ณ ๊ณ์๋๊ตฐ์!
| if isRange(x: currentX, y: col) { | ||
| // print("Hi") | ||
| queue.append((currentX, col)) | ||
| visitedGraph[currentX][col] = true | ||
| connectCnt += 1 | ||
| // print("COL", currentX, col) | ||
| } | ||
| } | ||
|
|
||
| pointer += 1 | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๊ฐ์ ํ์ด๋ก ๋ก๊ทธ ์ฐ์ผ๋ฉด ํท๊ฐ๋ฆฌ์์ง ์์ผ์ จ๋์? ใ ใ
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ ์ ์ฝ๋๋ ๊ทธ๋ฅ ์ผ๋ฐ ๋ฐฐ์ด ์ฌ๋ฌ๊ฐ ์์ฑํ๊ณ ์นด์ดํธํ๋๊ฒ์ด์์ด์ ์ฌ์ค ์ฒ์์ ๋ณด์๋ง์ BFS๋ก ํด์ผ๊ฒ ๋ค๋ผ๊ณ ๊ณ ๋ฏผ์์ด ๊ณ ํ๋ ค๋ค๊ฐ
์ ๋ ์คํ๋ ค ์์ด ๋ฌธ์ ๊ฐ ๋ ์กฐ๊ฑด์ด ํ์คํ๊ฑฐ๊ฐ์์ ์ข๋๋ผ๊ตฌ์ !!!
์ฌ๊ธฐ ๋ณด์๋๊ฒ์ฒ๋ผ ๋ฑ or๋ก ์ฃผ๋ ์ ๋ ๊ทธ๋ฅ ๋ฐฐ์ด์ ์นด์ดํธํด๋ ๊ด์ถํ์ง์์๊น ? 250250์ด์ด์ ์กฐ๊ฑด๋ถ๋ก ์นด์ดํ ํ๋ฉด ์ํ์ด ์๋๋ผ O(MN) ์ผ๋กํ ์ ์์ง์์๊น์๊ฐํ๋๊ฑฐ๊ฐ์์ !
class Solution {
func countServers(_ grid: [[Int]]) -> Int {
let m = grid.count
let n = grid[0].count
var rowCount = Array(repeating: 0, count: m)
var colCount = Array(repeating: 0, count: n)
for i in 0..<m {
for j in 0..<n{
if grid[i][j] == 1 {
rowCount[i] += 1
colCount[j] += 1
}
}
}
var result = 0
for i in 0..<m {
for j in 0..<n {
if grid[i][j] == 1 && (rowCount[i] > 1 || colCount[j] > 1) {
result += 1
}
}
}
return result
}
}๋ก ํ์์ต๋๋ค !!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์์ด ๋ฌธ์ ๊ฐ ๋ ์กฐ๊ฑด์ด ํ์คํ๊ฒ ๋๊ปด์ง์๋๊ตฐ์..
์ ๋ ๋ฐ~๋ก ํ์ด์ง ๋ฒ์ญ๊ธฐ ๋๋ ธ์๋๋ค.........
.....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@giljihun ๊ธธใ ใ ์ฌ์ค ์ ๋ ์์ด ๊ฒ๋ ๋ชปํฉ๋๋คใ ใ ใ ๋ญ๋๊น or? and ? ๋ ผ๋ฆฌ์ฐ์ฐ์๊ฐ ์ข ๋ ์ง๊ด์ ์ธ๊ฑฐ๊ฐ๋๋ผ๊ตฌ์ !!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ด์ผ ๋ฐ๋ฏธ์์ค์ ํญ์ runTime์์์ ๋ญํฌ๋์๋ค์ฉ.. ๋ฆฌ์คํ
๊ฐ์ ํ์ด๋ก ๋ก๊ทธ ์ฐ์ผ๋ฉด ํท๊ฐ๋ฆฌ์์ง ์์ผ์ จ๋์? ใ ใ
A : ๋ค ์ฃผ์๋์ด์์ด์ ๊ทธ๋๋ณด์ด์ค ์ ์์ง๋ง,, ํญ์ ํ์ชฝ์ ์ฃผ์์ผ๊ฑฐ๋ผ ๊ด์ฐฎ์ต๋๋ค..ใ ใ ์ฌ์ค ๋ ๋ช ํํ๊ฒ ๋ก๊ทธ์ฐ์ด์ฃผ๋๊ฒ ๋ ์ด์์ ์ด๊ธดํฉ๋๋ค.. ๋ค์๋ฒ์ ๊ทธ๋ ๊ฒ ํด๋ณผ๊ฒ์ฉ.
์์ด ๋ฌธ์ ๊ฐ ๋ ์กฐ๊ฑด์ด ํ์คํ๊ฒ ๋๊ปด์ง์๋๊ตฐ์..
A : ์ ๋ ์์์ผ์ด์ค๋ณด๊ณ ์ ๋ชจ๋ฅด๊ฒ ๋ค์ถ์ผ๋ฉด ๋ฐ๋ก ๋ฒ์ญ๊ธฐ๋ก..
giljihun
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
๋ฆฌํธ ์ฝ๋๋ ํญ์ ๋๋ ต๋ค์.
| func isRange(x: Int, y: Int) -> Bool { | ||
| return x >= 0 && y >= 0 && x < grid.count && y < grid[0].count && grid[x][y] == 1 && visitedGraph[x][y] == false | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isRange()๋ฅผ ๋ณด๊ณ ์ ๊ฐ๋ ์ฑ ์ธก๋ฉด์์ ์กฐ๊ธ ๋ฆฌํฉํ ๋งํ๋ฉด ์ข์ง์์๊น? ์๊ฐ์ด ๋ค์์ด์!
ํ์ฌ isRange()๋ ๋ฒ์ ์ฒดํฌ, ์๋ฒ ์ ํจ์ฑ?( == 1 + ๋ฐฉ๋ฌธ ์ฌ๋ถ)๋ฅผ ํจ๊ป ์ฒ๋ฆฌํ๊ณ ์๋๊ฑธ๋ก ๋ณด์ฌ์.
์๋ฏธ๋ ๋ช
ํํ๋ฐ, ์ด๊ฒ ๋ญ์ณ์์ด์ ๊ฐ๋
์ฑ์ด ์กฐ๊ธ ๋จ์ด์ง ์ ์๋ค? ์๊ฐ์ด ๋ค์ด์!
func isValidServer(x: Int, y: Int) -> Bool {
guard (0..<grid.count).contains(x),
(0..<grid[0].count).contains(y) else { return false }
return grid[x][y] == 1 && !visitedGraph[x][y]
}- guard๋ฅผ ํ์ฉํด๋ณด์ฃ !! ๋ฒ์ ์ฒดํฌ๋ฅผ ๋จผ์ ํด์ main ์กฐ๊ฑด์ ๋ ์ง์คํด๋ณด๋ ๊ฒ๋๋ค.
- ํจ์๋ช ๋ ์กฐ๊ธ ๋ ๋ฉ์ธ ๊ธฐ๋ฅ์ ์ง์คํด์ ๋ฐ๊ฟ๋ดค์ต๋๋ค.
๊ทธ ๋ณธ ์ฝ๋์ ์ ์ฉํด๋ ์กฐ๊ธ๋ง ๋ฐ๊พธ๋ฉด ๋ฌธ์ ์์ ๊ฒ ๊ฐ์์ ์๋ง๋..?!!?!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ฐ์ ๊ธธ์ ์๋ ๋ฆฌ๋ทฐ๋ ํญ์ ํ๋ฆฌํฐ๊ฐ ์ฐธ ์ข๋ค๊ณ ๋๋๋๋ค..
์์ ์ ์ฒ์ DFS/BFS๋ฐฐ์ธ๋๋ isRange๊ฐ ๋ง์ ๊ฒ์ ์ํํ์ง์์์๋๋ฐ,
๋ฌธ์ ๋ฅผ ํ์๋ก ๋ ๊น๋ํ๊ฒ ์์ถํ๊ณ ์ถ์ ์์ฌ์ ์ด๋์๊ฐ ์ด๋ฆ๋ง isRange์ง ๋ค ํด์ฃผ๊ณ ์์๋ค์..
guard์จ์ฃผ์ ์ผ๋ฌด์ง ํจ์ ํ ์ ๋ฐฐ์๊ฐ๋๋ค..!
- ํ๋ก๊ทธ๋๋จธ์ค ์์ํธํ๋ง๋ ๊ฒ ๊ฐ์์..! ์ผ๋จ ์ ๋ ฅ๋ฐ์๋์ ๋ถํธํจ์ด ์์ด์ ์ฐธ ์ข์ต๋๋น ( ๊ฒฐ์ ํ๋ฉด ๋๋ฒ๊น ์ ๋น๋กฏํ ์ถ๊ฐ์ ์ธ ๊ธฐ๋ฅ๋ ์๋ ๋ฏํด์)
alstjr7437
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
์ด๋ฒ์ฃผ์ฐจ ๋ฐ๋น ์ ๋ฌธ์ ๋ฅผ ์์ง ๋ชปํ์ด๋ดฃ๋ค์ ใ
ใ
๋ฆฌ๋ทฐ๋ ๋ค๋ฅธ ๋ถ๋ค์ด ๋๋ฌด ์๋ฌ์์ฃผ์
์ ๋ช๊ฐ ์ฝ๋ฉํธ ์ถ๊ฐ๋ฐ์ ์์์ด์ ใ
๋ค์๋ถํฐ ์ํ๋๋ก ํ๊ฒ ์ต๋๋ค!
| while pointer < queue.count { | ||
| let tmp = queue[pointer] | ||
| let currentX = tmp.0, currentY = tmp.1 | ||
|
|
||
| // ๊ตด๋ฌ๊ฐ ์ ์๋์ง ํ์ธ / 2์ฐจ ํ์ด : ์ฌ์ค์ ์ด๋ถ๋ถ๋ง ๊ณ ์ณ์ฃผ๋ฉด ๋ ๊ฒ๊ฐ์๋ฐ, ํ - ์ด์ด๋ผ | ||
|
|
||
| // ํ ๊ณ์ฐ | ||
| for row in 0 ..< grid.count { | ||
| // print("next:", nextX, nextY) | ||
| if isRange(x: row, y: currentY) { | ||
| // print("Hi") | ||
| queue.append((row, currentY)) | ||
| visitedGraph[row][currentY] = true | ||
| connectCnt += 1 | ||
| // print("ROW", row, currentY) | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ํ ์ ์ง ๋ญ๊ฐ ์ต์ํ๋ค ์ถ์๋๋ฐ ๊ทธ๋ ์๊ฐ์ ๋ฐ์์ ์์ฐ๊ณ ๊ณ์๋๊ตฐ์!




๐ ๋ฌธ์ ๋งํฌ
1267. Count Servers that Communicate
โ๏ธ ์์๋ ์๊ฐ
50๋ถ
โจ ์๋ ์ฝ๋
BFSํ์ด
connectCntํ๋๋ง ์๋ ์ปดํจํฐ๋ ์์ฉ์ ๋ชปํ๊ธฐ ๋๋ฌธ์ ํ๋๋ ์นด์ดํ ํด์ฃผ๊ธดํ๋๋ฐ BFS๋๋ฉด์ ์ด๊ฒ 1๋ณด๋ค ์ปค์ก์๋(์ฆ, ํต์ ๋๋ ๋ค๋ฅธ ์ปดํจํฐ ์น๊ตฌ๋ฅผ ๋ง๋ฌ์๋ ์ด์ ๊ทธ ๊ฐ์ด ์ค์ ์ ๋ต์นด์ดํธanswer์ ์ถ๊ฐ๊ฐ ๋๋ ๊ตฌ์กฐ์ ๋๋ค.์ธ์ ํ ์ปดํจํฐ๊ฐ ์๋๋ค ?!
๊ฐ์ ํ๊ณผ ์ด์ ๊ตฌํ๋ผ ํ๋๋ผ๊ตฌ์.. ๋ฌธ์ ๋ฅผ ์ ๋๋ก ์ฝ์ด์ผ๊ฒ ์ต๋๋ค.
Two servers are said to communicate if they are on the same row or on the same column.
์ด๋ ๊ฒ ๊ทธ๋ฅ ์ผ๋ฐ์ ์ธ DFS ์ธ์ ์ฐพ๊ธฐ์์ ,, ์๋์ฒ๋ผ ๋ณ๊ฒฝํด์คฌ์ต๋๋ค.
Index out of range
๋ฅผ ๋น๋กฏํด์
for row in 0 ..< grid[0].count , for col in 0 ..< grid.count์๋ค๊ฐ ๊ณ์ ํ๋ ค์ ๋ณด๋๊น ๋ฐ๋์๋ค์..for row in 0 ..< grid.count , for col in 0 ..< grid[0].count๊ธํ๊ฒ ํ์ด์ ๋งจ๋ ํ๋ฆฌ๊ณ ๋ฐ๊พธ๊ณ ํ๋ค๋ณด๋ ์ ๋๋ฆ๋๋ก์ ๊ธฐ์ค์ด ๋์กํ๋๋ด ๋๋ค.. ์ดํ์ ํ๋ฆฌ๊ธฐ์ ์ ๋ฐ๊พธ๋๋ก ๋ ธ๋ ฅํด๋ณด๊ฒ ์ต๋๋ท..
๊ฐ์
์๋ง ํ ๊ณผ ์ด์ ์๋ ์ปดํจํฐ ์ฐพ๋ ๋ก์ง์ด ์ ๋ ๊ฒ ๋์ถฉ ์ฒ๋ฆฌํด์ฃผ๋๊ฒ ์๋๋ผ ๋ ์ข์ ๋ฐฉ์์ด ์์ ๊ฒ ๊ฐ์๋ฐ, ํ ๋ฒ ๋ฆฌ๋ทฐํด์ฃผ์๋ฉด ์ข์ ๊ฒ ๊ฐํ์..! ์ธ์ ๊ฐ๊ธฐ์ ์ ํผ๊ฑฐ๋ผ ์ ๋ ์ฐพ์๋ณด๊ณ ๊ณต์ ๋๋ฆฌ๋๋ก ํ๊ฒ ์ต๋๋ค..!