Skip to content

Commit 49b00fe

Browse files
solves house robber
1 parent 801842d commit 49b00fe

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https://github.com/anishLearnsToCode/leetcode-algorithms)
44
![made-with-java](https://img.shields.io/badge/Made%20with-Java-1f425f.svg)
55
![made-with-python](https://img.shields.io/badge/Made%20with-Python-1f425f.svg)
6-
![problems-solved](https://img.shields.io/badge/Problems%20Solved-30/1412-1abc9c.svg)
7-
![problems-solved-java](https://img.shields.io/badge/Java-30/1412-1abc9c.svg)
8-
![problems-solved-python](https://img.shields.io/badge/Python-2/1412-1abc9c.svg)
6+
![problems-solved](https://img.shields.io/badge/Problems%20Solved-45/1412-1abc9c.svg)
7+
![problems-solved-java](https://img.shields.io/badge/Java-44/1412-1abc9c.svg)
8+
![problems-solved-python](https://img.shields.io/badge/Python-3/1412-1abc9c.svg)
99
[![license](https://img.shields.io/badge/LICENSE-MIT-<COLOR>.svg)](LICENSE)
1010
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](CONTRIBUTING.md)
1111

@@ -59,7 +59,7 @@
5959
| 189 | [Rotate Array](https://leetcode.com/problems/rotate-array) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/RotateArray.java) |
6060
| 190 | [Reverse Bits](https://leetcode.com/problems/reverse-bits) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/src/ReverseBits.java) |
6161
| 191 | [Number of One Bits](https://leetcode.com/problems/number-of-1-bits) | Easy | [![Python](https://img.icons8.com/color/35/000000/python.png)](https://github.com/anishLearnsToCode/leetcode-algorithms/blob/master/python/number_of_1_bits.py) |
62-
| 198 | [House Robber](https://leetcode.com/problems/house-robber) | Easy |
62+
| 198 | [House Robber](https://leetcode.com/problems/house-robber) | Easy | [![Java](https://img.icons8.com/color/40/000000/java-coffee-cup-logo.png)]() |
6363
| 202 | [Happy Number](https://leetcode.com/problems/happy-number) | Easy |
6464
| 203 | [Remove Linked List Elements](https://leetcode.com/problems/remove-linked-list-elements) | Easy |
6565
| 204 | [Count Primes](https://leetcode.com/problems/count-primes) | Easy |

src/HouseRobber.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
public class HouseRobber {
2+
public static int rob(int[] array) {
3+
if (array.length == 0) return 0;
4+
5+
int[] memory = new int[array.length + 1];
6+
memory[1] = array[0];
7+
for (int index = 1 ; index < array.length ; index++) {
8+
memory[index + 1] = Math.max(memory[index], memory[index - 1] + array[index]);
9+
}
10+
return memory[memory.length - 1];
11+
}
12+
}

0 commit comments

Comments
 (0)