MCPcopy Create free account
hub / github.com/Hsinha11/Leetcode-solutions / Solution

Class Solution

198-house-robber/house-robber.java:3–19  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1// House Robber - LeetCode #198
2
3class Solution {
4 public int rob(int[] nums) {
5 if (nums.length == 0) return 0;
6 if (nums.length == 1) return nums[0];
7
8 int prev = nums[0];
9 int curr = Math.max(nums[0], nums[1]);
10
11 for (int i = 2; i < nums.length; i++) {
12 int temp = Math.max(prev + nums[i], curr);
13 prev = curr;
14 curr = temp;
15 }
16
17 return curr;
18 }
19}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected