Skip to content

Commit 3082344

Browse files
committed
Coin Change
1 parent e683bd1 commit 3082344

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

β€Žcoin-change/haung921209.mdβ€Ž

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# μ—°κ΄€ 링크
2+
- [문제 풀이 μŠ€μΌ€μ€„](https://github.com/orgs/DaleStudy/projects/6/views/5)
3+
- [λ‹΅μ•ˆ μ½”λ“œ μ œμΆœλ²•](https://github.com/DaleStudy/leetcode-study/wiki/%EB%8B%B5%EC%95%88-%EC%A0%9C%EC%B6%9C-%EA%B0%80%EC%9D%B4%EB%93%9C)
4+
5+
# Problem
6+
- 문제 링크 : https://leetcode.com/problems/coin-change/description/
7+
- 문제 이름 : Coin Change
8+
- 문제 번호 : 322
9+
- λ‚œμ΄λ„ : Medium
10+
- μΉ΄ν…Œκ³ λ¦¬ : BFS
11+
12+
# 문제 μ„€λͺ…
13+
14+
15+
# 아이디어
16+
- bfs
17+
18+
# βœ… μ½”λ“œ (Solution)
19+
```
20+
class Solution {
21+
public:
22+
int coinChange(vector<int>& coins, int amount) {
23+
if(amount==0){
24+
return 0;
25+
}
26+
vector<int> res(amount + 1, -1);
27+
queue<int> q;
28+
for (auto coin : coins) {
29+
if (coin > amount) {
30+
continue;
31+
}
32+
if (coin == amount) {
33+
return 1;
34+
}
35+
res[coin] = 1;
36+
q.push(coin);
37+
}
38+
while (q.size()) {
39+
int curCoin = q.front();
40+
q.pop();
41+
int nextCount = res[curCoin] + 1;
42+
for (auto coin : coins) {
43+
int nextCoin = curCoin + coin;
44+
if (nextCoin > amount) {
45+
continue;
46+
}
47+
if (res[nextCoin] != -1) {
48+
continue;
49+
}
50+
if (nextCoin == amount) {
51+
return nextCount;
52+
}
53+
res[nextCoin] = nextCount;
54+
q.push(nextCoin);
55+
}
56+
}
57+
return res[amount];
58+
}
59+
};
60+
61+
```
62+
# πŸ” μ½”λ“œ μ„€λͺ…
63+
64+
65+
# μ΅œμ ν™” 포인트 (Optimality Discussion)
66+
β€’ μ΅œμ ν™”ν•œ μ΄μœ μ™€ 원리
67+
β€’ 더 쀄일 수 μžˆλŠ” μ—¬μ§€λŠ” μžˆλŠ”κ°€?
68+
β€’ κΈ°μ‘΄ 방법 λŒ€λΉ„ μ–Όλ§ˆλ‚˜ νš¨μœ¨μ μ΄μ—ˆλŠ”μ§€
69+
70+
# πŸ§ͺ ν…ŒμŠ€νŠΈ & μ—£μ§€ μΌ€μ΄μŠ€
71+
72+
# πŸ“š κ΄€λ ¨ 지식 볡슡
73+
74+
# πŸ” 회고
75+
76+

0 commit comments

Comments
Β (0)