LoginSignup
0
0

More than 3 years have passed since last update.

Leetcode #198: House Robber

Last updated at Posted at 2019-06-03
func rob(_ nums: [Int]) -> Int {
    if nums.isEmpty {
        return 0
    }
    var dp = Array(repeating: 0, count: nums.count+1)
    dp[1] = nums[0]
    for i in stride(from: 1, to: nums.count, by: 1) {
        dp[i+1] = max(dp[i-1] + nums[i], dp[i])
    }
    return dp[nums.count]
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0