We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent e86e2dc commit e80ccfeCopy full SHA for e80ccfe
ruby/198-House-Robber.rb
@@ -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