Skip to content

Commit 59d5f07

Browse files
authored
Create Solution3.cpp
1 parent 504e67f commit 59d5f07

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Solution {
2+
public:
3+
int rob(vector<int>& nums) {
4+
int f = 0, g = 0;
5+
for (int& x : nums) {
6+
int ff = max(f, g);
7+
g = f + x;
8+
f = ff;
9+
}
10+
return max(f, g);
11+
}
12+
};

0 commit comments

Comments
 (0)