An experienced robber aims to steal the money in the houses on a street. Each house has a certain amount of money hidden, but there is a catch: the security systems in adjacent houses are interconnected. If the robber breaks into two neighboring houses, the police will be alerted.
Given an array of integers numbers
where each element represents the amount of money in a house, determine the maximum amount of money the robber can steal without triggering the alarm.
numbers: number[]
: An array of integersInput: numbers = [1,2,3,1]Output: 4Explanation: The robber can steal a maximum of 4 by robbing house at index 0 (value 1) and house at index 2 (value 3).
Input: numbers = [2,7,9,3,1]Output: 12Explanation: The robber can steal a maximum of 12 by robbing house at index 0 (value 2), house at index 2 (value 9), and house at index 4 (value 1).
Input: numbers = [3,6,1,0,6,0,0,9]Output: 21Explanation: The robber can steal a maximum of 21 by robbing house at index 1 (value 6), house at index 4 (value 6), house at index 7 (value 9).
numbers.length
<= 100numbers[i]
<= 400An experienced robber aims to steal the money in the houses on a street. Each house has a certain amount of money hidden, but there is a catch: the security systems in adjacent houses are interconnected. If the robber breaks into two neighboring houses, the police will be alerted.
Given an array of integers numbers
where each element represents the amount of money in a house, determine the maximum amount of money the robber can steal without triggering the alarm.
numbers: number[]
: An array of integersInput: numbers = [1,2,3,1]Output: 4Explanation: The robber can steal a maximum of 4 by robbing house at index 0 (value 1) and house at index 2 (value 3).
Input: numbers = [2,7,9,3,1]Output: 12Explanation: The robber can steal a maximum of 12 by robbing house at index 0 (value 2), house at index 2 (value 9), and house at index 4 (value 1).
Input: numbers = [3,6,1,0,6,0,0,9]Output: 21Explanation: The robber can steal a maximum of 21 by robbing house at index 1 (value 6), house at index 4 (value 6), house at index 7 (value 9).
numbers.length
<= 100numbers[i]
<= 400console.log()
语句将显示在此处。