LeetCode # 1518
Example 1:
Input:
numBottles = 9, numExchange = 3
Output: 13
Explanation: You can exchange 3 empty bottles to get 1 full water bottle. Number of water bottles you can drink: 9 + 3 + 1 = 13.
Constraints:
- 1 <= numBottles <= 100
- 2 <= numExchange <= 100
Solution #1 (0ms)
class Solution {
public int numWaterBottles(int numBottles, int numExchange) {
int answer = numBottles;
while (numBottles >= numExchange) {
answer += numBottles / numExchange;
numBottles = numBottles / numExchange + numBottles % numExchange;
}
return answer;
}
}
Result #1
More Algorithm!
👇👇
github.com/ggujangi/ggu.leet-code
출처 : leetCode
'LeetCode > Easy' 카테고리의 다른 글
[Java] LeetCode 953 : Verifying an Alien Dictionary (0) | 2021.04.21 |
---|---|
[Java] LeetCode 874 : Walking Robot Simulation (0) | 2021.04.17 |
[Java] LeetCode 290 : Word Pattern (0) | 2021.04.17 |
[Java] LeetCode 914 : X of a Kind in a Deck of Cards (0) | 2021.04.17 |
[Java] LeetCode 1486 : XOR Operation in an Array (0) | 2021.04.17 |