From decee370e30d43c7a09abbfd885a137c864d009c Mon Sep 17 00:00:00 2001 From: "daeho.kim" Date: Fri, 13 Dec 2024 13:13:42 +0900 Subject: [PATCH 1/5] feat: 217. Contains Duplicate --- contains-duplicate/hodaessi.py | 10 ++++++++++ 1 file changed, 10 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..6203bcf24 --- /dev/null +++ b/contains-duplicate/hodaessi.py @@ -0,0 +1,10 @@ +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 a3e7172a88a0e4187d53be0795fcafb9713a6707 Mon Sep 17 00:00:00 2001 From: "daeho.kim" Date: Fri, 13 Dec 2024 13:21:50 +0900 Subject: [PATCH 2/5] feat: 347. Top K Frequent Elements --- top-k-frequent-elements/hodaessi.py | 9 +++++++++ 1 file changed, 9 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..f9a0fd6f4 --- /dev/null +++ b/top-k-frequent-elements/hodaessi.py @@ -0,0 +1,9 @@ +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 cac4c9909a89a6cf59319f6a809766a72c3404db Mon Sep 17 00:00:00 2001 From: "daeho.kim" Date: Fri, 13 Dec 2024 17:34:35 +0900 Subject: [PATCH 3/5] feat: 125. Valid Palindrome --- valid-palindrome/hodaessi.py | 7 +++++++ 1 file changed, 7 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..48b8b02ff --- /dev/null +++ b/valid-palindrome/hodaessi.py @@ -0,0 +1,7 @@ +class Solution: + def isPalindrome(self, s: str) -> bool: + s = s.lower() + + s = ''.join(filter(str.isalnum, s)) + + return s == s[::-1] From 5ca3f225db417d8e2af40ee8bf232da69fb26ec3 Mon Sep 17 00:00:00 2001 From: "daeho.kim" Date: Fri, 13 Dec 2024 18:17:38 +0900 Subject: [PATCH 4/5] feat: 128. Longest Consecutive Sequence --- longest-consecutive-sequence/hodaessi.py | 37 ++++++++++++++++++++++++ 1 file changed, 37 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..70985c662 --- /dev/null +++ b/longest-consecutive-sequence/hodaessi.py @@ -0,0 +1,37 @@ +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 2dc3cd460c2f9225648fcbc73876062cef6146ea Mon Sep 17 00:00:00 2001 From: "daeho.kim" Date: Fri, 13 Dec 2024 19:40:15 +0900 Subject: [PATCH 5/5] feat: 198. House Robber --- house-robber/hodaessi.py | 14 ++++++++++++++ 1 file changed, 14 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..40d72b861 --- /dev/null +++ b/house-robber/hodaessi.py @@ -0,0 +1,14 @@ +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)