[์๊ณ ๋ฆฌ์ฆ/Swift] ๊ทธ๋ํํ์(DFS/BFS) - ํ๊ฒ๋๋ฒ, ๋คํธ์ํฌ, ๋จ์ด๋ณํ, ์ฌํ๊ฒฝ๋ก
1. ํ๊ฒ ๋๋ฒ (DFS) 1์ ๋ํ๊ฑฐ๋ ๋บ ์ ์๊ธฐ ๋๋ฌธ์, ๋ํ๊ฑฐ๋ ๋นผ๋ ๊ฒฝ์ฐ์ ๋ํด ํ๋ฒ์ฉ DFS ๋ฅผ ์ํํด์ค๋ค. ์ด๋ฅผ ๊ทธ๋ํ๋ก ๊ทธ๋ ค๋ณด๋ฉด ์ดํดํ๊ธฐ ์ฝ๋ค. ์ซ์๋ฅผ ํ๋ ๋ํ๊ฑฐ๋ ๋นผ๋ ๊ฒ์ ๊ทธ๋ํ์ ๊น์ด ํ์์ด๋ผ๊ณ ์๊ฐํ๋ฉด ๋๋ค. import Foundation func dfs(numbers: [Int], target: Int, i: Int, total: Int) -> Int { if i == numbers.count { return total == target ? 1 : 0 } let count1 = dfs(numbers: numbers, target: target, i: i+1, total: total - numbers[i]) let count2 = dfs(numbers: numbers, targe..
2021. 7. 21.