Skip to content

Commit 688c7c4

Browse files
committed
week01_4_5_solution
1 parent 4942fc3 commit 688c7c4

2 files changed

Lines changed: 36 additions & 0 deletions

File tree

house-robber/YOOHYOJEONG.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# https://leetcode.com/problems/house-robber/
2+
3+
class Solution(object):
4+
def rob(self, nums):
5+
6+
prev = 0
7+
prev_2 = 0
8+
9+
for num in nums:
10+
cur = max(prev, prev_2 + num)
11+
12+
prev_2 = prev
13+
prev = cur
14+
15+
return prev
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# https://leetcode.com/problems/longest-consecutive-sequence/
2+
3+
class Solution(object):
4+
def longestConsecutive(self, nums):
5+
6+
nums_set = set(nums)
7+
lens = 0
8+
9+
for n in nums_set:
10+
11+
if n-1 not in nums_set:
12+
cur = n
13+
lenth = 1
14+
15+
while cur+1 in nums_set:
16+
cur += 1
17+
lenth += 1
18+
19+
lens = max(lens, lenth)
20+
21+
return lens

0 commit comments

Comments
 (0)