File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change 1
1
class Solution {
2
2
/**
3
3
* ๊ธฐ์กด house-robber 1 ๋ฌธ์ ์์ ๋ก์ง์ ๊ฐ์ ธ์ค๋, ์ ๊ทผ๋ฒ์ ๋ฌ๋ฆฌํ๋ ๋ฌธ์
4
+ * ์ฒ์์๊ฐํ๋ ์ ๊ทผ๋ฒ์ ๊ทธ๋ฅ dp๊ฐ์์ ์ฒซ๋ฒ์งธ ๋๋ ๋ง์ง๋ง ์์๋ฅผ ๋นผ์ ๋์จ ์ต๋๊ฐ ์๋๊ฐ? ํ์ง๋ง ๋ฒ์์ ๋ฐ๋ผ dp๊ฐ ๋ฌ๋ผ์ง๋ฏ๋ก ์ค๋ต
4
5
*/
5
6
public int rob (int [] nums ) {
6
7
if (nums .length == 1 ) return nums [0 ];
Original file line number Diff line number Diff line change
1
+ class Solution {
2
+ /**
3
+ * ์ฒ์์๋ set ์๋ฃ๊ตฌ์กฐ๋ฅผ ๋์ํด์ ๊ผญ ๋น ์ง ์ซ์๋ฅผ ์ฐพ๊ฒ ๋ค๊ณ ๋ค์งํ์ผ๋,
4
+ * ์๊ฐํด๋ณด๋ ๋จ์ํ ๋ฒ์๊ฐ 0๋ถํฐ nums.length๊น์ง์ ์ฐ์๋ ์ํ์ค๋ผ๋ฉด
5
+ * ๊ทธ๋ฅ 0๋ถํฐ n๊น์ง ๋ํ์ ๋์ ์๋ ์์๊ฐ์์ ํ์ฌ nums์ ํฉ๊ณ๋ฅผ ๋นผ๋ฉด ๋๋ ๊ฒ์ด๋ค.
6
+ *
7
+ * ์ต๋๊ฐ, ์ต์๊ฐ์ ๊ตฌํ ๋์ ๋น์ทํ๊ฒ ๊ตณ์ด ๋ด์ฉ ์์ ๋ค ์ฐพ์ผ๋ ค๊ณ ํ์ ์๋ฃ๊ตฌ์กฐ์ ์ฝ๋งค์ด์ง ์์๋ ๋๋ค.
8
+ */
9
+ public int missingNumber (int [] nums ) {
10
+ int expected = 0 ; // 0๋ถํฐ n๊น์ง ๋ํ ์ซ์์ ํฉ๊ณ
11
+ int input = 0 ; //nums๊ฐ ์ค ์ซ์๋ค์ ํฉ๊ณ
12
+
13
+ for (int n : nums ) {
14
+ input += n ;
15
+ }
16
+
17
+ for (int i = 0 ; i <= nums .length ; i ++) {
18
+ expected += i ;
19
+ }
20
+ // System.out.println(expected + " and " + input);
21
+
22
+ return expected - input ;
23
+ }
24
+ }
You canโt perform that action at this time.
0 commit comments