Skip to content

Commit 404d1f5

Browse files
authored
Merge pull request #693 from HodaeSsi/main
[HodaeSsi] Week 1
2 parents 36ac323 + 6f69170 commit 404d1f5

File tree

5 files changed

+82
-0
lines changed

5 files changed

+82
-0
lines changed

contains-duplicate/HodaeSsi.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from typing import List
2+
3+
class Solution:
4+
def containsDuplicate(self, nums: List[int]) -> bool:
5+
dict = {}
6+
for num in nums:
7+
dict[num] = dict.get(num, 0) + 1
8+
if dict[num] > 1:
9+
return True
10+
return False
11+

house-robber/HodaeSsi.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def rob(self, nums: List[int]) -> int:
6+
dp = [0] * len(nums)
7+
8+
for i in range(len(nums)-1, -1, -1):
9+
dpMax = 0
10+
for j in range(i + 2, len(nums)):
11+
dpMax = max(dpMax, dp[j])
12+
dp[i] = nums[i] + dpMax
13+
14+
return max(dp)
15+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from typing import List
2+
3+
4+
class Node:
5+
def __init__(self, value):
6+
self.value = value
7+
self.parent = None
8+
self.child = None
9+
10+
class Solution:
11+
def longestConsecutive(self, nums: List[int]) -> int:
12+
answer = 0
13+
dict = {}
14+
15+
for num in nums:
16+
if dict.get(num) is None:
17+
dict[num] = Node(num)
18+
if dict.get(num + 1) is not None:
19+
dict[num + 1].child = dict[num]
20+
dict[num].parent = dict[num + 1]
21+
22+
if dict.get(num - 1) is not None:
23+
dict[num].child = dict[num - 1]
24+
dict[num - 1].parent = dict[num]
25+
26+
for key in dict.keys():
27+
if dict[key].parent is None:
28+
node = dict[key]
29+
count = 1
30+
31+
while node.child is not None:
32+
count += 1
33+
node = node.child
34+
35+
answer = max(answer, count)
36+
37+
return answer
38+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from typing import List
2+
3+
class Solution:
4+
def topKFrequent(self, nums: List[int], k: int) -> List[int]:
5+
dict = {}
6+
for num in nums:
7+
dict[num] = dict.get(num, 0) + 1
8+
9+
return sorted(dict.keys(), key=lambda x: dict[x], reverse=True)[:k]
10+

valid-palindrome/HodaeSsi.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class Solution:
2+
def isPalindrome(self, s: str) -> bool:
3+
s = s.lower()
4+
5+
s = ''.join(filter(str.isalnum, s))
6+
7+
return s == s[::-1]
8+

0 commit comments

Comments
 (0)