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 27b0a93 commit 054993dCopy full SHA for 054993d
house-robber/jeongwoo903.js
@@ -0,0 +1,19 @@
1
+/**
2
+ * @param {number[]} nums
3
+ * @return {number}
4
+ */
5
+
6
+// dp 개념을 이용
7
8
+var rob = function(nums) {
9
+ if(nums.length == 0) { return 0 };
10
+ if(nums.length == 1) { return nums[0] };
11
12
+ nums[1] = Math.max(nums[0], nums[1]);
13
14
+ for(let i = 2; i < nums.length; i++) {
15
+ nums[i] = Math.max(nums[i-2] + nums[i], nums[i-1])
16
+ }
17
18
+ return nums[nums.length - 1];
19
+};
0 commit comments