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 044cdcf commit 5e33f02Copy full SHA for 5e33f02
1 file changed
house-robber/Yu-Won.js
@@ -0,0 +1,19 @@
1
+/**
2
+ * 문제: https://leetcode.com/problems/house-robber/description/
3
+ *
4
+ * 요구사항:
5
+ * nums: number[]를 Input 으로 받았을 때
6
+ * 인접하지 않은 데이터들의 합 중 가장 큰 값을 리턴한다.
7
8
+ * * */
9
+
10
+const houseRobber = (nums) => {
11
+ let prev1 = 0;
12
+ let prev2 = 0;
13
+ for(let i = 0; i < nums.length; i++) {
14
+ let current = Math.max(nums[i] + prev2, prev1);
15
+ prev2 = prev1;
16
+ prev1 = current;
17
+ }
18
+ return prev1;
19
+}
0 commit comments