Skip to content

Commit 4247144

Browse files
committed
[week1] House Robber - gmlwls96
1 parent c299218 commit 4247144

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

house-robber/gmlwls96.kt

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package leetcode_study
2+
3+
import java.lang.Integer.max
4+
5+
class Solution {
6+
fun rob(nums: IntArray): Int {
7+
return max(rob_recursion(nums, 0), rob_recursion(nums, 1))
8+
}
9+
10+
private fun rob_recursion(nums: IntArray, index: Int): Int {
11+
if (index >= nums.size) {
12+
return 0
13+
}
14+
return nums[index] + rob_recursion(nums, index + 2)
15+
}
16+
}

0 commit comments

Comments
 (0)