File tree Expand file tree Collapse file tree 1 file changed +76
-0
lines changed
Expand file tree Collapse file tree 1 file changed +76
-0
lines changed Original file line number Diff line number Diff line change 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+
You canβt perform that action at this time.
0 commit comments