728x90
leetcode.com/problems/water-bottles/
변수 설정 애매하게 해서 돌아돌아 맞춘 정답...🤦♀️
class Solution {
public int numWaterBottles(int numBottles, int numExchange) {
int drink = numBottles;
while (numBottles >= numExchange){
drink += numBottles / numExchange;
numBottles = numBottles / numExchange + numBottles % numExchange;
}
return drink;
}
}
728x90
'코딩테스트' 카테고리의 다른 글
[LeetCode] 1051. Height Checker (0) | 2021.04.24 |
---|---|
[LeetCode] 831. Masking Personal Information (0) | 2021.04.24 |
[LeetCode] 202. Happy Number (0) | 2021.04.21 |
[LeetCode] 268. Missing Number (4) | 2021.04.19 |
[LeetCode] 27. Remove Element (0) | 2021.04.17 |