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 091c502 commit cbb7de6Copy full SHA for cbb7de6
house-robber/hyer0705.ts
@@ -0,0 +1,14 @@
1
+function rob(nums: number[]): number {
2
+ const n = nums.length;
3
+
4
+ const dp: number[][] = Array.from({ length: n }, () => Array(2).fill(0));
5
6
+ dp[0][1] = nums[0];
7
8
+ for (let i = 1; i < n; i++) {
9
+ dp[i][0] = Math.max(dp[i - 1][0], dp[i - 1][1]);
10
+ dp[i][1] = dp[i - 1][0] + nums[i];
11
+ }
12
13
+ return Math.max(...dp[n - 1]);
14
+}
0 commit comments