From 0d6efd4b5ef4b108c70360c5b0ca7ab4b2f8c2fa Mon Sep 17 00:00:00 2001 From: E-1on Date: Wed, 2 Apr 2025 21:27:02 +0900 Subject: [PATCH 1/6] Contains Duplicate --- contains-duplicate/Sung-Heon.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 contains-duplicate/Sung-Heon.py diff --git a/contains-duplicate/Sung-Heon.py b/contains-duplicate/Sung-Heon.py new file mode 100644 index 000000000..a7baaf57e --- /dev/null +++ b/contains-duplicate/Sung-Heon.py @@ -0,0 +1,9 @@ +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + temp = {} + for i in nums: + if temp.get(i): + return True + else: + temp[i] = True + return False \ No newline at end of file From 0711835fac42f27d1cea015e22c3f269d96d42c6 Mon Sep 17 00:00:00 2001 From: E-1on Date: Wed, 2 Apr 2025 21:28:40 +0900 Subject: [PATCH 2/6] Top K --- top-k-frequent-elements/Sung-Heon.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 top-k-frequent-elements/Sung-Heon.py diff --git a/top-k-frequent-elements/Sung-Heon.py b/top-k-frequent-elements/Sung-Heon.py new file mode 100644 index 000000000..9923bfd09 --- /dev/null +++ b/top-k-frequent-elements/Sung-Heon.py @@ -0,0 +1,9 @@ +class Solution: + def topKFrequent(self, nums: List[int], k: int) -> List[int]: + temp = {} + for i in nums: + if temp.get(i): + temp[i] += 1 + else: + temp[i] = 1 + return [key for key, value in sorted(temp.items(), key=lambda x: x[1],reverse=True)][:k] \ No newline at end of file From c2c53ac5db7ae0faa645026c1f385622fbd2c59d Mon Sep 17 00:00:00 2001 From: E-1on Date: Wed, 2 Apr 2025 21:29:50 +0900 Subject: [PATCH 3/6] longest consecutive --- longest-consecutive-sequence/Sung-Heon.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 longest-consecutive-sequence/Sung-Heon.py diff --git a/longest-consecutive-sequence/Sung-Heon.py b/longest-consecutive-sequence/Sung-Heon.py new file mode 100644 index 000000000..8fede8eb8 --- /dev/null +++ b/longest-consecutive-sequence/Sung-Heon.py @@ -0,0 +1,21 @@ +class Solution: + def longestConsecutive(self, nums: List[int]) -> int: + if not nums: + return 0 + + num_set = set(nums) + longest = 0 + + visited = set() + + for num in num_set: + if num not in visited and num - 1 not in num_set: + current = num + current_streak = 0 + while current in num_set: + visited.add(current) + current_streak += 1 + current += 1 + longest = max(longest, current_streak) + + return longest \ No newline at end of file From 1c9ecfdf3e2311319053ad78a238fef1ba1ca75c Mon Sep 17 00:00:00 2001 From: E-1on Date: Wed, 2 Apr 2025 21:30:57 +0900 Subject: [PATCH 4/6] houser robber --- house-robber/Sung-Heon.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 house-robber/Sung-Heon.py diff --git a/house-robber/Sung-Heon.py b/house-robber/Sung-Heon.py new file mode 100644 index 000000000..f60d18460 --- /dev/null +++ b/house-robber/Sung-Heon.py @@ -0,0 +1,15 @@ +class Solution: + def rob(self, nums: List[int]) -> int: + if len(nums) == 1: + return nums[0] + if len(nums) == 2: + return max(nums) + + dp = [0] * len(nums) + dp[0] = nums[0] + dp[1] = max(nums[0], nums[1]) + + for i in range(2, len(nums)): + dp[i] = max(dp[i - 2] + nums[i], dp[i - 1]) + + return dp[-1] \ No newline at end of file From 2c2c8d27b88870b5bc21f58b32536c41a668957e Mon Sep 17 00:00:00 2001 From: E-1on Date: Fri, 4 Apr 2025 09:39:52 +0900 Subject: [PATCH 5/6] line-lint --- contains-duplicate/Sung-Heon.py | 2 +- house-robber/Sung-Heon.py | 2 +- longest-consecutive-sequence/Sung-Heon.py | 2 +- top-k-frequent-elements/Sung-Heon.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/contains-duplicate/Sung-Heon.py b/contains-duplicate/Sung-Heon.py index a7baaf57e..38710d294 100644 --- a/contains-duplicate/Sung-Heon.py +++ b/contains-duplicate/Sung-Heon.py @@ -6,4 +6,4 @@ def containsDuplicate(self, nums: List[int]) -> bool: return True else: temp[i] = True - return False \ No newline at end of file + return False diff --git a/house-robber/Sung-Heon.py b/house-robber/Sung-Heon.py index f60d18460..444c60bdb 100644 --- a/house-robber/Sung-Heon.py +++ b/house-robber/Sung-Heon.py @@ -12,4 +12,4 @@ def rob(self, nums: List[int]) -> int: for i in range(2, len(nums)): dp[i] = max(dp[i - 2] + nums[i], dp[i - 1]) - return dp[-1] \ No newline at end of file + return dp[-1] diff --git a/longest-consecutive-sequence/Sung-Heon.py b/longest-consecutive-sequence/Sung-Heon.py index 8fede8eb8..7a14ca926 100644 --- a/longest-consecutive-sequence/Sung-Heon.py +++ b/longest-consecutive-sequence/Sung-Heon.py @@ -18,4 +18,4 @@ def longestConsecutive(self, nums: List[int]) -> int: current += 1 longest = max(longest, current_streak) - return longest \ No newline at end of file + return longest diff --git a/top-k-frequent-elements/Sung-Heon.py b/top-k-frequent-elements/Sung-Heon.py index 9923bfd09..593bb74d6 100644 --- a/top-k-frequent-elements/Sung-Heon.py +++ b/top-k-frequent-elements/Sung-Heon.py @@ -6,4 +6,4 @@ def topKFrequent(self, nums: List[int], k: int) -> List[int]: temp[i] += 1 else: temp[i] = 1 - return [key for key, value in sorted(temp.items(), key=lambda x: x[1],reverse=True)][:k] \ No newline at end of file + return [key for key, value in sorted(temp.items(), key=lambda x: x[1], reverse=True)][:k] From 20b652fb32be915e1d30f0468e497eba5db479b4 Mon Sep 17 00:00:00 2001 From: E-1on Date: Fri, 4 Apr 2025 09:47:45 +0900 Subject: [PATCH 6/6] two-sum --- two-sum/Sung-Heon.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 two-sum/Sung-Heon.py diff --git a/two-sum/Sung-Heon.py b/two-sum/Sung-Heon.py new file mode 100644 index 000000000..96527fea7 --- /dev/null +++ b/two-sum/Sung-Heon.py @@ -0,0 +1,8 @@ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + temp = {} + for i, num in enumerate(nums): + if target - num in temp: + return [i, temp[target - num]] + temp[num] = i + return None