일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | |
7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 | 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | 24 | 25 | 26 | 27 |
28 | 29 | 30 |
Tags
- 백준알고리즘
- 카페
- 임파선전이
- 알고리즘
- Compose
- 갑상선암
- 객체
- kotlin
- 프로그래머스
- 정렬 알고리즘
- 수술
- 코틀린
- 림프절전이
- Android
- 폐CT
- 안드로이드
- android auto
- 자바
- 저요오드식
- 맛집
- leetcode
- java
- 입원
- 방사성동위원소치료
- 전이
- 동위원소치료
- 방사성 동위원소 치료
- firebase
- Android Compose
- MYSQL
Archives
- Today
- Total
새우버거의 개발 블로그
[Java] LeetCode 1518 : Water Bottles 본문
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
'알고리즘 > LeetCode' 카테고리의 다른 글
[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 |