Skip to content

Commit a4cd96d

Browse files
Merge pull request #2071 from CodingTestStudy2/이진희
[이진희] Day22
2 parents b56a586 + 676302f commit a4cd96d

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
3+
1. 아이디어 : 거스름돈을 줄 수 있는지 체크
4+
10$ -> 5$ 1장
5+
20$ -> 5$ 3장 or 10$ + 5$
6+
7+
2. 시간복잡도 : O(N)
8+
9+
3. 자료구조/알고리즘 : 완전탐색, 조건문
10+
11+
*/
12+
13+
class Solution {
14+
public boolean lemonadeChange(int[] bills) {
15+
16+
// 5 10
17+
int[] money = new int[2];
18+
19+
for(int i=0; i<bills.length; i++) {
20+
int pay = bills[i];
21+
22+
if(pay == 5) money[0]++;
23+
else if(pay == 10) {
24+
if(money[0] == 0) return false;
25+
money[1]++;
26+
money[0]--;
27+
}
28+
else {
29+
// 5$ 3장 or 10$ + 5$
30+
if(money[0]>0 && money[1]>0) {
31+
money[0]--;
32+
money[1]--;
33+
}
34+
else if (money[0] > 2) money[0] -=3;
35+
else return false;
36+
}
37+
}
38+
39+
return true;
40+
}
41+
}

0 commit comments

Comments
 (0)