Skip to content

Commit 8b429ff

Browse files
committed
5 not solved
1 parent 6cbf6b0 commit 8b429ff

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

contains-duplicate/devyulbae.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""
2-
Blind75 - 3. Contains Duplicate
2+
Blind75 - 1. Contains Duplicate
33
https://leetcode.com/problems/contains-duplicate/
44
55
Counter를 사용한 풀이

house-robber/devyulbae.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""
2+
blind75 - House Robber
3+
LeetCode Problem: https://leetcode.com/problems/house-robber/
4+
5+
재귀
6+
F(x) = F(x+1), F(x+2) + nums[x] 중 큰 값을 계속 선택하면 된다
7+
-> 재귀를 2번씩 호출하기 때문에 시간복잡도는 O(2^n)으로 Time Limit Exceeded 발생
8+
다음 주차 때 다시 풀어보자.
9+
dp로도 될 거 같다
10+
"""
11+
12+
from typing import List
13+
14+
class Solution:
15+
def rob(self, nums: List[int]) -> int:
16+
if not nums:
17+
return 0
18+
19+
def dfs(s):
20+
if s >= len(nums):
21+
return 0
22+
return max(dfs(s+1), nums[s] + dfs(s+2))
23+
24+
return dfs(0)
25+
26+

longest-consecutive-sequence/devyulbae.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,28 @@
33
https://leetcode.com/problems/longest-consecutive-sequence/
44
55
조건 : O(n) 시간복잡도
6+
1. 시작점이면 초기화
7+
2. 아니면 cnt++
8+
3. 끊기면 max 갱신
69
"""
7-
10+
from typing import List
811

912
class Solution:
1013
def longestConsecutive(self, nums: List[int]) -> int:
11-
14+
if len(nums) == 0:
15+
return 0
16+
nums.sort()
17+
length = 1
18+
max_length = 0
19+
for i in range(len(nums)-1):
20+
if nums[i+1] == nums[i]:
21+
continue
22+
elif nums[i+1] == nums[i] + 1:
23+
length += 1
24+
else:
25+
max_length = max(max_length, length)
26+
length = 1
27+
28+
max_length = max(max_length, length)
29+
return max_length
30+

0 commit comments

Comments
 (0)