Skip to content

Commit 068cede

Browse files
committed
feat: add solutions to lc problem: No.0198
No.0198.House Robber
1 parent 834f7a4 commit 068cede

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

solution/0100-0199/0198.House Robber/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,32 @@ func max(a, b int) int {
116116
}
117117
```
118118

119+
### **TypeScript**
120+
121+
```ts
122+
function rob(nums: number[]): number {
123+
const dp = [0, 0];
124+
for (const num of nums) {
125+
[dp[0], dp[1]] = [dp[1], Math.max(dp[1], dp[0] + num)];
126+
}
127+
return dp[1];
128+
}
129+
```
130+
131+
### **Rust**
132+
133+
```rust
134+
impl Solution {
135+
pub fn rob(nums: Vec<i32>) -> i32 {
136+
let mut dp = [0, 0];
137+
for num in nums {
138+
dp = [dp[1], dp[1].max(dp[0] + num)]
139+
}
140+
dp[1]
141+
}
142+
}
143+
```
144+
119145
### **...**
120146

121147
```

solution/0100-0199/0198.House Robber/README_EN.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,32 @@ func max(a, b int) int {
103103
}
104104
```
105105

106+
### **TypeScript**
107+
108+
```ts
109+
function rob(nums: number[]): number {
110+
const dp = [0, 0];
111+
for (const num of nums) {
112+
[dp[0], dp[1]] = [dp[1], Math.max(dp[1], dp[0] + num)];
113+
}
114+
return dp[1];
115+
}
116+
```
117+
118+
### **Rust**
119+
120+
```rust
121+
impl Solution {
122+
pub fn rob(nums: Vec<i32>) -> i32 {
123+
let mut dp = [0, 0];
124+
for num in nums {
125+
dp = [dp[1], dp[1].max(dp[0] + num)]
126+
}
127+
dp[1]
128+
}
129+
}
130+
```
131+
106132
### **...**
107133

108134
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
impl Solution {
2+
pub fn rob(nums: Vec<i32>) -> i32 {
3+
let mut dp = [0, 0];
4+
for num in nums {
5+
dp = [dp[1], dp[1].max(dp[0] + num)]
6+
}
7+
dp[1]
8+
}
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function rob(nums: number[]): number {
2+
const dp = [0, 0];
3+
for (const num of nums) {
4+
[dp[0], dp[1]] = [dp[1], Math.max(dp[1], dp[0] + num)];
5+
}
6+
return dp[1];
7+
}

0 commit comments

Comments
 (0)