File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
find-minimum-in-rotated-sorted-array Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 1+ import java .util .Arrays ;
2+
3+ class Solution {
4+ public int coinChange (int [] coins , int amount ) {
5+ int max =amount +1 ;
6+ int [] dp =new int [amount +1 ];
7+ Arrays .fill (dp ,max );
8+ dp [0 ]=0 ;
9+ for (int coin :coins ){
10+ for (int j =coin ;j <=amount ;j ++){ // coin๋ถํฐ ์์ํด์ ์ผ๋ฐ ๋ฃจํ๋ณด๋ค ์ฑ๋ฅ ํฅ์
11+ dp [j ]=Math .min (dp [j ],dp [j -coin ]+1 );
12+ }
13+ }
14+ return dp [amount ]>amount ? -1 :dp [amount ];
15+ }
16+ }
Original file line number Diff line number Diff line change @@ -15,13 +15,17 @@ public int findMin(int[] nums) {
1515 int mid = left + (right - left ) / 2 ;
1616
1717 // ์ค๊ฐ๊ฐ์ด ์ค๋ฅธ์ชฝ๊ฐ๋ณด๋ค ํฌ๋ค๋ฉด ์ผ์ชฝ ํฌ์ธํฐ๋ฅผ ์ค๊ฐ๊ฐ+1๋ก ์ฆ๊ฐํฉ๋๋ค.
18- if (nums [mid ] > nums [right ]) {
18+ if (nums [mid ] > nums [right ]) { // <= ์ ๋์ผ
1919 left = mid + 1 ;
2020 } else {
2121 // ์ค๊ฐ๊ฐ๋ณด๋ค ์ค๋ฅธ์ชฝ๊ฐ์ด ํฌ๋ค๋ฉด ์ค๊ฐ๊ฐ์ด ์ต๋ ๋ฒ์๊ฐ ๋์ด์ผ ํฉ๋๋ค.
22+ // ์ต์๊ฐ์ด mid์ผ ๊ฐ๋ฅ์ฑ์ด ์๊ธฐ ๋๋ฌธ์ด๋ค.
2223 right = mid ;
2324 }
2425 }
2526 return nums [left ];
2627 }
2728}
29+
30+ // ์ฒ์์๋ ์ ํ ์ด์ง ํ์์ผ๋ก์ left = mid+1, right = mid-1์ ํ์ผ๋ ์คํจ
31+ // ํ์ง๋ง ์ต์ ์ซ์๋ ๋ฌด์กฐ๊ฑด left๊ฐ ๊ฐ๋ฆฌํค๋ ๊ฐ์.
You canโt perform that action at this time.
0 commit comments