Skip to content

Commit 9dfc6e1

Browse files
authored
Update 213-house-robber-ii.js
1 parent a2fa57d commit 9dfc6e1

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

213-house-robber-ii.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,27 @@ const rob = function(nums) {
1717
return Math.max(startFromFirst[nums.length - 1], startFromSecond[nums.length])
1818

1919
};
20+
21+
// another
22+
23+
/**
24+
* @param {number[]} nums
25+
* @return {number}
26+
*/
27+
const rob = function(nums) {
28+
const n = nums.length
29+
nums = nums.concat(nums)
30+
let res = 0
31+
for(let i = 0; i < n; i++) {
32+
let tmp = nums[i]
33+
let pp = 0
34+
let p = 0
35+
for(let j = i; j < n + i - 1; j++) {
36+
tmp = Math.max(tmp, pp + nums[j], p);
37+
[pp, p] = [p, tmp]
38+
}
39+
res = Math.max(res, tmp)
40+
}
41+
42+
return res
43+
};

0 commit comments

Comments
 (0)