From 21ee0e741755b732d527fa464dd28523afc3b309 Mon Sep 17 00:00:00 2001 From: "daeho.kim" Date: Fri, 13 Dec 2024 20:01:25 +0900 Subject: [PATCH 1/5] feat: 217. Contains Duplicate --- contains-duplicate/hodaessi.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 contains-duplicate/hodaessi.py diff --git a/contains-duplicate/hodaessi.py b/contains-duplicate/hodaessi.py new file mode 100644 index 000000000..21c2e5478 --- /dev/null +++ b/contains-duplicate/hodaessi.py @@ -0,0 +1,11 @@ +from typing import List + +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + dict = {} + for num in nums: + dict[num] = dict.get(num, 0) + 1 + if dict[num] > 1: + return True + return False + From 6131df462ffc570334885b49fc1aae834c59b6bf Mon Sep 17 00:00:00 2001 From: "daeho.kim" Date: Fri, 13 Dec 2024 20:02:43 +0900 Subject: [PATCH 2/5] feat: 347. Top K Frequent Elements --- top-k-frequent-elements/hodaessi.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 top-k-frequent-elements/hodaessi.py diff --git a/top-k-frequent-elements/hodaessi.py b/top-k-frequent-elements/hodaessi.py new file mode 100644 index 000000000..a902dd124 --- /dev/null +++ b/top-k-frequent-elements/hodaessi.py @@ -0,0 +1,10 @@ +from typing import List + +class Solution: + def topKFrequent(self, nums: List[int], k: int) -> List[int]: + dict = {} + for num in nums: + dict[num] = dict.get(num, 0) + 1 + + return sorted(dict.keys(), key=lambda x: dict[x], reverse=True)[:k] + From 3e5d426cd62d8596fecd06da9dd6f1093ea2d3ce Mon Sep 17 00:00:00 2001 From: "daeho.kim" Date: Fri, 13 Dec 2024 20:05:22 +0900 Subject: [PATCH 3/5] feat: 125. Valid Palindrome --- valid-palindrome/hodaessi.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 valid-palindrome/hodaessi.py diff --git a/valid-palindrome/hodaessi.py b/valid-palindrome/hodaessi.py new file mode 100644 index 000000000..a63636611 --- /dev/null +++ b/valid-palindrome/hodaessi.py @@ -0,0 +1,8 @@ +class Solution: + def isPalindrome(self, s: str) -> bool: + s = s.lower() + + s = ''.join(filter(str.isalnum, s)) + + return s == s[::-1] + From 28b892f5d4586f48a7beefb076d6e207248e8586 Mon Sep 17 00:00:00 2001 From: "daeho.kim" Date: Fri, 13 Dec 2024 20:06:40 +0900 Subject: [PATCH 4/5] feat: 128. Longest Consecutive Sequence --- longest-consecutive-sequence/hodaessi.py | 38 ++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 longest-consecutive-sequence/hodaessi.py diff --git a/longest-consecutive-sequence/hodaessi.py b/longest-consecutive-sequence/hodaessi.py new file mode 100644 index 000000000..9ba623c57 --- /dev/null +++ b/longest-consecutive-sequence/hodaessi.py @@ -0,0 +1,38 @@ +from typing import List + + +class Node: + def __init__(self, value): + self.value = value + self.parent = None + self.child = None + +class Solution: + def longestConsecutive(self, nums: List[int]) -> int: + answer = 0 + dict = {} + + for num in nums: + if dict.get(num) is None: + dict[num] = Node(num) + if dict.get(num + 1) is not None: + dict[num + 1].child = dict[num] + dict[num].parent = dict[num + 1] + + if dict.get(num - 1) is not None: + dict[num].child = dict[num - 1] + dict[num - 1].parent = dict[num] + + for key in dict.keys(): + if dict[key].parent is None: + node = dict[key] + count = 1 + + while node.child is not None: + count += 1 + node = node.child + + answer = max(answer, count) + + return answer + From 9b899729565821bd4124dc1b53aa146df4e047fa Mon Sep 17 00:00:00 2001 From: "daeho.kim" Date: Fri, 13 Dec 2024 20:07:32 +0900 Subject: [PATCH 5/5] feat: 198. House Robber --- house-robber/hodaessi.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 house-robber/hodaessi.py diff --git a/house-robber/hodaessi.py b/house-robber/hodaessi.py new file mode 100644 index 000000000..b68bcdc36 --- /dev/null +++ b/house-robber/hodaessi.py @@ -0,0 +1,15 @@ +from typing import List + + +class Solution: + def rob(self, nums: List[int]) -> int: + dp = [0] * len(nums) + + for i in range(len(nums)-1, -1, -1): + dpMax = 0 + for j in range(i + 2, len(nums)): + dpMax = max(dpMax, dp[j]) + dp[i] = nums[i] + dpMax + + return max(dp) +