| 1 | // House Robber - LeetCode #198 |
| 2 | |
| 3 | class 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 | } |
nothing calls this directly
no outgoing calls
no test coverage detected