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
- 코테
- array
- implement
- Tree
- greedy
- Binary Search
- database
- two pointers
- geometry
- Binary Tree
- Class
- Method
- hash table
- Stack
- bit manipulation
- Matrix
- Data Structure
- sorting
- simulation
- 자바
- java
- Math
- string
- 구현
- SQL
- Counting
- 파이썬
- dynamic programming
- 코딩테스트
- Number Theory
Archives
- Today
- Total
코린이의 소소한 공부노트
[LeetCode/Easy] 860. Lemonade Change 본문
1. Input
1) 고객들이 지불한 금액이 순서대로 담긴 int 배열 bills
2. Output
1) 고객들에게 맞는 잔돈을 지불할 수 있다면 true, 아니면 false 반환
2) 레모네이드 한잔에 5원이다
3) 화폐는 5원, 10원, 20원의 3종류가 있고, 고객은 이 중 하나를 지불한다.
4) 나는 잔돈 없이 장사를 시작하고, 갖고 있는 돈 내에서 고객에게 잔돈을 지불해줘야 한다.
3. Constraint
1) 1 <= bills.length <= 10^5
4. Example
Input: bills = [5,5,10,10,20] -> Output: false
설명:
- 첫 번째 고객 -> 잔돈X -> 수중에 5원 1개
- 두 번째 고객 -> 잔돈X -> 수중에 5원 2개
- 세 번째 고객 -> 잔돈 5 -> 수중에 5원 1개, 10원 1개
- 네 번째 고객 -> 잔돈 5 -> 수중에 10원 1개
- 다섯 번째 고객 -> 잔돈 15 -> 지불 불가 -> false 반환
5. Code
1) 첫 코드(2022/07/26)
int hand5 = 0;
int hand10 = 0;
for(int i=0 ; i<bills.length ; i++){
if(bills[i]==10){
if(hand5<1)
return false;
else{
hand10++;
hand5--;
}
} else if(bills[i]==20){
if(!(hand5>=3 || (hand5>=1 && hand10>=1)))
return false;
else{
if(hand10>=1){
hand10--;
hand5--;
} else{
hand5 -= 3;
}
}
} else
hand5 += 1;
}
return true;
'코딩테스트 풀이 > JAVA' 카테고리의 다른 글
[LeetCode/Easy] 883. Projection Area of 3D Shapes (0) | 2022.12.09 |
---|---|
[LeetCode/Easy] 867. Transpose Matrix (0) | 2022.12.08 |
[LeetCode/Easy] 832. Flipping an Image (0) | 2022.12.08 |
[LeetCode/Easy] 824. Goat Latin (0) | 2022.12.08 |
[LeetCode/Easy] 821. Shortest Distance to a Character (0) | 2022.12.08 |