๐ ์ฝํ
/ํ๋ก๊ทธ๋๋จธ์ค
[Swift] ํ๋ก๊ทธ๋๋จธ์ค150368 ์ด๋ชจํฐ์ฝ ํ ์ธํ์ฌ
JerryiOS
2023. 5. 9. 17:28
import Foundation
func solution(_ users:[[Int]], _ emoticons:[Int]) -> [Int] {
var answer = [0, 0]
func getAnswer(_ current: [Int]) {
if current.count > emoticons.count { return }
stride(from: 10, through: 40, by: 10).forEach { getAnswer(current + [$0]) }
if current.count < emoticons.count { return }
var result = [0, 0]
users.forEach { user in
var userInfo = [0, 0]
for i in current.indices {
if current[i] >= user[0] {
userInfo[1] += emoticons[i] * (100 - current[i]) / 100
}
if userInfo[1] >= user[1] {
userInfo = [1, 0]
break
}
}
result[0] += userInfo[0]
result[1] += userInfo[1]
}
if result[0] > answer[0] || (result[0] == answer[0] && result[1] > answer[1]) {
answer = result
}
}
getAnswer([Int]())
return answer
}
๋ฐ์ํ