Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 | 31 |
Tags
- hash table
- greedy
- 자바
- bit manipulation
- Math
- Binary Search
- Tree
- simulation
- SQL
- Stack
- 코테
- 구현
- implement
- sorting
- string
- Number Theory
- geometry
- java
- Method
- Counting
- Data Structure
- dynamic programming
- database
- 파이썬
- Binary Tree
- Class
- 코딩테스트
- array
- two pointers
- Matrix
Archives
- Today
- Total
코린이의 소소한 공부노트
[프로그래머스/Lv.1] 콜라 문제 본문
1. Input, Output, Example
- 콜라를 받기 위해 마트에 주어야 하는 병 수 a, 빈 병 a개를 가져다 주면 마트가 주는 콜라 병 수 b, 상빈이가 가지고 있는 빈 병의 개수 n이 주어질 때, 일반화된 콜라 문제를 해결하는 프로그램을 작성하시오.
2. Constraint
1) 1 ≤ b < a ≤ n ≤ 1,000,000
2) 정답은 항상 int 범위를 넘지 않게 주어진다.
3. Code
class Solution {
public int solution(int a, int b, int n) {
int coke = 0;
while(n>=a){
coke += (n/a)*b;
n = n%a + (n/a)*b;
}
return coke;
}
}
- +1
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 2697. Lexicographically Smallest Palindrome (0) | 2023.06.30 |
---|---|
[프로그래머스/Lv.1] 명예의 전당 (1) (0) | 2023.06.30 |
[프로그래머스/Lv.1] 문자열 내 마음대로 정렬하기 (0) | 2023.06.30 |
[프로그래머스/Lv.0] 특이한 정렬 (0) | 2023.06.30 |
[LeetCode/Easy] 2696. Minimum String Length After Removing Substrings (0) | 2023.06.30 |