House Robber
A street has a row of houses, and nums[i] is the amount of cash kept in house i. Neighbouring houses share an alarm: if two adjacent houses are both robbed on the same night, it goes off.
Return the largest total amount of cash you can take without ever robbing two adjacent houses. You may skip as many houses as you like, including several in a row.
Constraints
1 <= nums.length <= 1000 <= nums[i] <= 400
Examples
Example 1
Input: nums = [4,1,2,7,5,3,1] Output: 14
Rob houses 0, 3 and 5: 4 + 7 + 3 = 14. No two of them are neighbours.
Example 2
Input: nums = [6,2,1,8] Output: 14
Houses 0 and 3: 6 + 8. Skipping two houses in a row is allowed, and here it pays off.
Example 3
Input: nums = [3,10,3] Output: 10
The middle house alone beats the two outer ones (3 + 3 = 6).
JavaScript you'll use: Arrays: create, read, update Numbers, Math and integer tricks
/**
* @param {number[]} nums
* @return {number}
*/
function rob(nums) {
}
Ctrl/⌘ + ' runs the examples, Ctrl/⌘ + Enter submits. Use console.log freely: output shows under Console. In the editor, press Esc then Tab to move focus out.