Skip to content

Commit 4863243

Browse files
committed
[DP] Update solution to House Robber
1 parent 60b6fef commit 4863243

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

DP/HouseRobber.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@
77

88
class HouseRobber {
99
func rob(nums: [Int]) -> Int {
10-
var curt = 0, prev = 0, res = 0
10+
var curt = 0, prev = 0
1111

1212
for num in nums {
13-
res = max(cur, prev + num)
14-
(curt, prev) = (res, curt)
13+
(curt, prev) = (max(curt, prev + num), curt)
1514
}
1615

17-
return res
16+
return curt
1817
}
1918
}

0 commit comments

Comments
 (0)