Skip to content

Commit 6cd8ee9

Browse files
committed
add: houseRobber solution
1 parent e0d74da commit 6cd8ee9

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

house-robber/Cyjin-jani.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const rob = function (nums) {
2+
// 최대 누적값을 저장하는 배열
3+
const data = [];
4+
data[0] = nums[0];
5+
6+
for (let i = 1; i < nums.length; i++) {
7+
data[i] = Math.max(data[i - 1], (data[i - 2] ?? 0) + nums[i]);
8+
}
9+
10+
return data[data.length - 1];
11+
};

0 commit comments

Comments
 (0)