We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent bd65038 commit dff59b1Copy full SHA for dff59b1
โhouse-robber/hanseulhee.js
@@ -0,0 +1,20 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @return {number}
4
+ */
5
+
6
+var rob = function (nums) {
7
+ // ์ง์ด ํ๋์ธ ๊ฒฝ์ฐ
8
+ if (nums.length === 1) return nums[0]
9
10
+ let prevMax = 0 // ๋ ์ง ์ ๊น์ง์ ์ต๋ ๊ธ์ก
11
+ let currMax = 0 // ์ด์ ์ง๊น์ง์ ์ต๋ ๊ธ์ก
12
13
+ for (let num of nums) {
14
+ let temp = currMax // ํ์ฌ ์ต๋ ๊ธ์ก
15
+ currMax = Math.max(currMax, prevMax + num) // ํ์ฌ ์ง์ ํธ๊ฑฐ๋ ํธ์ง ์์ ๊ฒฝ์ฐ ์ค ํฐ ๊ฐ
16
+ prevMax = temp // ์ด์ ์ง์ผ๋ก ์ด๋
17
+ }
18
19
+ return currMax // ์ต๋ ๊ธ์ก ๋ฐํ
20
+}
0 commit comments