Skip to content

Commit a3e3549

Browse files
authored
Merge pull request #849 from vfonic/house-robber
Create 198-House-Robber.rb
2 parents c882750 + 1e13f5f commit a3e3549

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

ruby/198-House-Robber.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# @param {Integer[]} nums
2+
# @return {Integer}
3+
def rob(nums)
4+
dp = Array.new(nums.size + 3) { 0 }
5+
6+
nums.each_with_index do |num, i|
7+
dp[i + 3] = num + [dp[i + 1], dp[i]].max
8+
end
9+
10+
[dp[-1], dp[-2]].max
11+
end

0 commit comments

Comments
 (0)