From f54580f1746b9bb0eb3b10cc73e93a74809fdd5c Mon Sep 17 00:00:00 2001 From: "daeho.kim" Date: Fri, 13 Dec 2024 20:14:37 +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 f0db96aa08265957ad10ef1d42dc54048c9c1832 Mon Sep 17 00:00:00 2001 From: "daeho.kim" Date: Fri, 13 Dec 2024 20:26:04 +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 46211b9d6013bf0888df6e82021edd1c2dcfdc97 Mon Sep 17 00:00:00 2001 From: "daeho.kim" Date: Fri, 13 Dec 2024 20:33:24 +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 1621698127b07c5c85e77f739cf6c3d1c45859bf Mon Sep 17 00:00:00 2001 From: "daeho.kim" Date: Fri, 13 Dec 2024 20:34:31 +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 6f69170fd8f5c1edfcea04c98e8313daf36791cb Mon Sep 17 00:00:00 2001 From: "daeho.kim" Date: Fri, 13 Dec 2024 20:35:28 +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) +