Skip to content

Commit 781921c

Browse files
committed
feat: Add solution for LeetCode problem 198
1 parent e94e807 commit 781921c

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

house-robber/WhiteHyun.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// 198. House Robber
3+
// https://leetcode.com/problems/house-robber/description/
4+
// Dale-Study
5+
//
6+
// Created by WhiteHyun on 2024/07/06.
7+
//
8+
9+
class Solution {
10+
func rob(_ nums: [Int]) -> Int {
11+
var previous = 0
12+
var current = 0
13+
14+
for element in nums {
15+
(previous, current) = (current, max(element + previous, current))
16+
}
17+
return max(previous, current)
18+
}
19+
}

0 commit comments

Comments
 (0)