Skip to content

Instantly share code, notes, and snippets.

@ykdojo
Created March 25, 2019 18:42
Show Gist options
  • Save ykdojo/5cd0f27684c4a6e5fe0dd45edec54f8e to your computer and use it in GitHub Desktop.
Save ykdojo/5cd0f27684c4a6e5fe0dd45edec54f8e to your computer and use it in GitHub Desktop.
/**
* @param {number[]} nums
* @return {number}
*/
var rob = function(nums) {
return helper(nums, 0);
};
var helper = function(nums, current) {
if (current > nums.length) {
return 0;
}
let option1 = nums[current] + helper(nums, current + 2);
let option2 = helper(nums, current + 1);
if (option1 >= option2) {
return option1;
}
else {
return option2;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment