LeetCode/Easy
[Java] LeetCode 1518 : Water Bottles
새우버거♬
2021. 4. 17. 18:22
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
ggujangi/ggu.leet-code
LeetCode, Java. Contribute to ggujangi/ggu.leet-code development by creating an account on GitHub.
github.com
출처 : leetCode