LeetCode House Robber

2394 단어 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 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 };

좋은 웹페이지 즐겨찾기