Skip to content

Commit f5d9e79

Browse files
committed
No198
1 parent bf233b1 commit f5d9e79

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

leetcode/DP/No198.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
class No198 {
2+
public int rob(int[] nums) {
3+
int a = 0;
4+
int b = 0;
5+
for (int i = 0; i < nums.length; i++) {
6+
if (i % 2 == 0) {
7+
a = Math.max(nums[i] + a, b);
8+
} else {
9+
b = Math.max(a, nums[i] + b);
10+
}
11+
}
12+
return Math.max(a, b);
13+
}
14+
}

0 commit comments

Comments
 (0)