Skip to content

Commit 9ec2f4f

Browse files
committed
198. House Robber in progress
1 parent ec5c781 commit 9ec2f4f

File tree

4 files changed

+80
-2
lines changed

4 files changed

+80
-2
lines changed

Medium/HouseRobber.ts

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* Problem: 198. House Robber
3+
* Acceptance Rate: 43.8%
4+
* URL: https://leetcode.com/problems/house-robber/
5+
*
6+
* Runtime:
7+
* Memory Usage:
8+
*/
9+
10+
export default function rob(houses: number[]): number {
11+
Solution.planHeist(houses);
12+
return Solution.rob(0, houses);
13+
}
14+
15+
class Solution {
16+
private static moneyRobbed: number;
17+
private static neighborhood: number[];
18+
19+
static planHeist(neighborhood: number[]) {
20+
Solution.neighborhood = neighborhood;
21+
}
22+
23+
static rob(startingHouseIndex: number, neighborhood: number[]): number {
24+
Solution.moneyRobbed = neighborhood[0];
25+
26+
for(let i=2; i < neighborhood.length; i+=2) {
27+
}
28+
29+
return 0;
30+
}
31+
32+
private static _moreValuableHouse(x: number, y: number): number {
33+
return Solution.neighborhood[x] > Solution.neighborhood[y] ? x : y;
34+
}
35+
36+
}
37+
38+
//---------------------------------------------------------------------
39+
// ---------- MAIN PROGRAM ----------
40+
//---------------------------------------------------------------------
41+
if(import.meta.main) {
42+
43+
rob([1,2,3,1]);
44+
// rob([2,7,9,3,1]);
45+
46+
// RUN: deno run medium/HouseRobber.ts
47+
}
48+
49+
// --------------------------- Terminal Output: ---------------------------

Medium/test/HouseRobber.test.ts

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { assertEquals } from '../../test_deps.ts';
2+
3+
import rob from '../HouseRobber.ts';
4+
5+
// RUN: deno test medium/test/HouseRobber.test.ts
6+
7+
//---------------------------------------------------------------------
8+
// ---------- UNIT TESTS ----------
9+
//---------------------------------------------------------------------
10+
11+
Deno.test({
12+
name: "[1,2,3,1] -> 4",
13+
fn() {
14+
let neighborhood = [1,2,3,1];
15+
assertEquals(rob(neighborhood), 4);
16+
}
17+
});
18+
19+
20+
21+
Deno.test({
22+
name: "[2,7,9,3,1] -> 12",
23+
fn() {
24+
let neighborhood = [2,7,9,3,1];
25+
assertEquals(rob(neighborhood), 12);
26+
}
27+
});

Medium/test/LongestPalindromicSubstring.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { assertEquals, assertNotEquals } from '../../test_deps.ts';
22

3-
import longestPalindromeIn from "../LongestPalindromicSubstring.ts";
3+
import longestPalindromeIn from '../LongestPalindromicSubstring.ts';
44

55

66
// RUN: deno test medium/test/LongestPalindromicSubstring.test.ts

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Leetcode Solutions in TypeScript
1+
# LeetCode Solutions in TypeScript
22

33
## Environment
44
- <span title="July 2021">Deno 1.12.0</span>
@@ -7,5 +7,7 @@
77

88
## Problems Completed
99

10+
Java Solutions – [CoffeelessProgrammer/leetcode-java](https://github.com/CoffeelessProgrammer/leetcode-java)
11+
1012
### Medium
1113
- <span title="Acceptance Rate: 31.0%">5. Longest Palindromic Substring</span>

0 commit comments

Comments
 (0)