Created
March 25, 2019 18:42
-
-
Save ykdojo/5cd0f27684c4a6e5fe0dd45edec54f8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @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