题解 | #打家劫舍(一)#
打家劫舍(一)
https://www.nowcoder.com/practice/c5fbf7325fbd4c0ea3d0c3ea6bc6cc79
class Solution { public: int rob(vector<int>& nums) { int prev = 0, cur = 0; for(int i = 0; i < nums.size(); i++){ int tmp = cur; cur = max(cur, prev + nums[i]); prev = tmp; } return cur; } };