213. House Robber II Medium

@problem@discussion
#Array#Dynamic Programming



1/**
2 * [213] House Robber II
3 *
4 * You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed. All houses at this place are arranged in a circle. That means the first house is the neighbor of the last one. Meanwhile, adjacent houses have a security system connected, and it will automatically contact the police if two adjacent houses were broken into on the same night.
5 * Given an integer array nums representing the amount of money of each house, return the maximum amount of money you can rob tonight without alerting the police.
6 *  
7 * Example 1:
8 * 
9 * Input: nums = [2,3,2]
10 * Output: 3
11 * Explanation: You cannot rob house 1 (money = 2) and then rob house 3 (money = 2), because they are adjacent houses.
12 * 
13 * Example 2:
14 * 
15 * Input: nums = [1,2,3,1]
16 * Output: 4
17 * Explanation: Rob house 1 (money = 1) and then rob house 3 (money = 3).
18 * Total amount you can rob = 1 + 3 = 4.
19 * 
20 * Example 3:
21 * 
22 * Input: nums = [1,2,3]
23 * Output: 3
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	1 <= nums.length <= 100
29 * 	0 <= nums[i] <= 1000
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/house-robber-ii/
35// discuss: https://leetcode.com/problems/house-robber-ii/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn rob(nums: Vec<i32>) -> i32 {
41        0
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_213() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.