그냥정렬치고 맨앞2개랑 int비교해서 int가 크면 빼고리턴 작으면 그냥리턴
정답
class Solution {
fun buyChoco(prices: IntArray, money: Int): Int {
val sortList = prices.sorted()
val chocoPrice=sortList[0]+sortList[1]
if ((money-chocoPrice)>=0){
return money-chocoPrice
}
return money
}
}
'알고리즘' 카테고리의 다른 글
릿코드 1422. Maximum Score After Splitting a String 코틀린 (0) | 2023.12.22 |
---|---|
릿코드 1637. Widest Vertical Area Between Two Points Containing No Points 코틀린 (0) | 2023.12.21 |
릿코드 661. Image Smoother 코틀린 (0) | 2023.12.19 |
릿코드 1913. Maximum Product Difference Between Two Pairs 코틀린 (0) | 2023.12.18 |
릿코드 242. Valid Anagram 코틀린 (0) | 2023.12.16 |