We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
💬 Idea
DFS를 이용하여 깊이우선탐색을 진행하며 +, - 연산을 수행하자
→ 재귀함수를 호출하자!
연산이 +, - 2가지 경우가 있으므로
💬 풀이
import Foundation var answer: Int = 0 func solution(_ numbers:[Int], _ target:Int) -> Int { dfs(numbers: numbers, target: target, index: 0, sum: 0) return answer } func dfs(numbers: [Int], target: Int, index: Int, sum: Int) { if index == numbers.count { if target == sum { answer += 1 } return } dfs(numbers: numbers, target: target, index: index + 1, sum: sum + numbers[index]) dfs(numbers: numbers, target: target, index: index + 1, sum: sum - numbers[index]) }
import Foundation var answer: Int = 0 func solution(_ numbers:[Int], _ target:Int) -> Int { dfs(numbers: numbers, target: target, index: 0, sum: 0) return answer } func dfs(numbers: [Int], target: Int, index: Int, sum: Int) { if index == numbers.count { if target == sum { answer += 1 } return } dfs(numbers: numbers, target: target, index: index + 1, sum: sum + numbers[index]) dfs(numbers: numbers, target: target, index: index + 1, sum: sum - numbers[index])
var answer: Int = 0
func solution(_ numbers:[Int], _ target:Int) -> Int { dfs(numbers: numbers, target: target, index: 0, sum: 0) return answer }
func dfs(numbers: [Int], target: Int, index: Int, sum: Int) { if index == numbers.count { if target == sum { answer += 1 } return }
dfs(numbers: numbers, target: target, index: index + 1, sum: sum + numbers[index]) dfs(numbers: numbers, target: target, index: index + 1, sum: sum - numbers[index])
}
소요시간 : 1시간 30분
소요시간
💬 알게된 것
DFS에서는 재귀함수 호출을, DFS에서는 큐 사용을 주로 하여 문제를 풀이한다는 것을 알게 되었다.
The text was updated successfully, but these errors were encountered:
#11 - 타겟 넘버 문제 풀이
2961e00
hwangJi-dev
No branches or pull requests
📌 TODO
🎢 타겟 넘버
💬 Idea
DFS를 이용하여 깊이우선탐색을 진행하며 +, - 연산을 수행하자
→ 재귀함수를 호출하자!
연산이 +, - 2가지 경우가 있으므로
💬 풀이
소요시간
: 1시간 30분💬 알게된 것
✅ DFS/BFS
DFS에서는 재귀함수 호출을, DFS에서는 큐 사용을 주로 하여 문제를 풀이한다는 것을 알게 되었다.
The text was updated successfully, but these errors were encountered: