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 50a2ffb commit f43803cCopy full SHA for f43803c
house-robber/hyunjung-choi.kt
@@ -0,0 +1,18 @@
1
+package leetcode_study
2
+
3
+class Solution {
4
+ fun rob(nums: IntArray): Int {
5
+ if (nums.size == 1) return nums[0]
6
7
+ var prev2 = nums[0]
8
+ var prev1 = maxOf(nums[0], nums[1])
9
10
+ for (i in 2 until nums.size) {
11
+ val current = maxOf(prev1, prev2 + nums[i])
12
+ prev2 = prev1
13
+ prev1 = current
14
+ }
15
16
+ return prev1
17
18
+}
0 commit comments