Skip to content

Commit

Permalink
Merge pull request #14 from cedard234/dev
Browse files Browse the repository at this point in the history
198 house robber
  • Loading branch information
cedard234 authored Oct 24, 2023
2 parents 4788d37 + ac64b75 commit cc49b34
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/cppstylecheck.yml

This file was deleted.

17 changes: 17 additions & 0 deletions cpp/198-House-Robber.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution {
public:
int rob(vector<int>& nums) {
int rob(vector<int>& nums) {
if (nums.empty()) return 0;
int n = nums.size();
if (n == 1) return nums[0];
int pre2 = 0, pre1 = 0, cur;
for (int i = 0; i < n; ++i) {
cur = max(pre2 + nums[i], pre1);
pre2 = pre1;
pre1 = cur;
}
return cur;
}
}
};

0 comments on commit cc49b34

Please sign in to comment.