Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add scala solution for 198-House-Robber
  • Loading branch information
ChrisKheng committed Aug 7, 2022
commit 30a9c51999474b8095d0d547dc3ba8932dc0c389
13 changes: 13 additions & 0 deletions scala/198-House-Robber.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
object Solution {
def rob(nums: Array[Int]): Int = {
var (prevTwoMaxProfit, prevMaxProfit) = (0, 0)

for (currCash <- nums) {
val currProfit = (currCash + prevTwoMaxProfit).max(prevMaxProfit)
prevTwoMaxProfit = prevMaxProfit
prevMaxProfit = currProfit
}

return prevMaxProfit
}
}