-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
💬 문제
[코딩테스트 연습 - 음양 더하기](https://school.programmers.co.kr/learn/courses/30/lessons/76501)
💬 풀이
func solution(_ absolutes:[Int], _ signs:[Bool]) -> Int {
var result = 0
for (index, absolute) in absolutes.enumerated() {
result += signs[index] == false ? -absolute : absolute
}
return result
}
💬 더 나은 방법?
func solution(_ absolutes:[Int], _ signs:[Bool]) -> Int {
return (0..<absolutes.count).map { signs[$0] ? absolutes[$0] : -absolutes[$0] }.reduce(0, +)
}