zoukankan      html  css  js  c++  java
  • LeetCode House Robber

    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 tonight without alerting the police.

    不是非常理解

     1 class Solution {
     2 public:
     3     int rob(vector<int> &num) {
     4         int hasrob = 0;
     5         int notrob = 0;
     6         
     7         for (int i=0; i<num.size(); i++) {
     8             int tnot = notrob;
     9             notrob = max(notrob, hasrob);
    10             hasrob = tnot + num[i];
    11         }
    12         return max(notrob, hasrob);
    13     }
    14 };
  • 相关阅读:
    Hibernate Validation注解列表
    Java_Shell多线程
    Lua读写文件
    shell导出和导入redis
    大文件读写
    Java_Hbase优化
    控制语句if
    字典(DICT)
    元组Tuple
    Session 会话
  • 原文地址:https://www.cnblogs.com/lailailai/p/4409992.html
Copyright © 2011-2022 走看看