标签:
1 class Solution { 2 public: 3 int rob(vector<int>& nums) { 4 if (nums.size() == 0) return 0; 5 if (nums.size() == 1) return nums[0]; 6 vector<int> money(nums.size(), 0); 7 money[0] = nums[0]; 8 money[1] = max(nums[0], nums[1]); 9 for (int i = 2; i < nums.size(); ++ i) { 10 money[i] = max(money[i - 1], money[i - 2] + nums[i]); 11 } 12 return money[nums.size() - 1]; 13 } 14 };
标签:
原文地址:http://www.cnblogs.com/shadowwalker9/p/5746791.html