leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0198.cpp (305B)


      1 class Solution {
      2   public:
      3     int rob(vector<int> &nums) {
      4         if (nums.size() == 0) return 0;
      5         int prev1 = 0, prev2 = 0;
      6         for (int num : nums) {
      7             int tmp = prev1;
      8             prev1 = max(prev2 + num, prev1);
      9             prev2 = tmp;
     10         }
     11         return prev1;
     12     }
     13 };