zoukankan      html  css  js  c++  java
  • 198. House Robber(LeetCode)

    You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will automatically contact the police if two adjacent houses were broken into on the same night.

    Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonightwithout alerting the police.

     1 class Solution {
     2 public:
     3     int rob(vector<int>& nums) {
     4        int len=nums.size();
     5         if (len == 0)
     6             return 0;
     7         if (len == 1)
     8             return nums.front();
     9         vector<int> vet(len, 0);
    10         vet[0] = nums[0];
    11         vet[1] = max(nums[0], nums[1]);
    12         
    13             for (int i = 2; i < len; i++)
    14             {
    15                 vet[i] = max(vet[i - 2]+nums[i],vet[i-1]);
    16             }
    17             
    18         
    19         return vet[len - 1];
    20         
    21     }
    22 };
  • 相关阅读:
    运算放大器
    阻抗模型
    mysql优化
    tomcat调优
    jvm调优
    springboot使用
    deploy工程到nexus
    Spring data elasticsearch使用
    kibana使用
    笔记
  • 原文地址:https://www.cnblogs.com/wujufengyun/p/7015942.html
Copyright © 2011-2022 走看看