MCPcopy Create free account
hub / github.com/neetcode-gh/leetcode / rob

Function rob

javascript/0213-house-robber-ii.js:8–19  ·  view source on GitHub ↗
(nums)

Source from the content-addressed store, hash-verified

6 * @return {number}
7 */
8var rob = (nums) => {
9 const isBaseCase1 = nums.length === 0;
10 if (isBaseCase1) return 0;
11
12 const isBaseCase2 = nums.length === 1;
13 if (isBaseCase2) return nums[0];
14
15 const left = search(nums, 0, nums.length - 2); /* Time O(N) */
16 const right = search(nums, 1, nums.length - 1); /* Time O(N) */
17
18 return Math.max(left, right);
19};
20
21const search = (nums, start, end) => {
22 let [left, mid] = [0, 0];

Callers

nothing calls this directly

Calls 1

searchFunction · 0.70

Tested by

no test coverage detected