leetcodeSolution to some Leetcode problems written in C++ |
git clone git://git.dimitrijedobrota.com/leetcode.git |
Log | Files | Refs | README | LICENSE |
0198.cpp (305B)
0 class Solution {
1 public:
2 int rob(vector<int> &nums) {
3 if (nums.size() == 0) return 0;
4 int prev1 = 0, prev2 = 0;
5 for (int num : nums) {
6 int tmp = prev1;
7 prev1 = max(prev2 + num, prev1);
8 prev2 = tmp;
9 }
10 return prev1;
11 }
12 };