From 29a569b6fe347d345a64a39ac932317bae36a411 Mon Sep 17 00:00:00 2001 From: Changhyun Lee Date: Mon, 9 Dec 2024 10:18:19 +0900 Subject: [PATCH 1/5] ADD : contains-duplicate/heypaprika.py --- contains-duplicate/heypaprika.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 contains-duplicate/heypaprika.py diff --git a/contains-duplicate/heypaprika.py b/contains-duplicate/heypaprika.py new file mode 100644 index 000000000..2aa679a9b --- /dev/null +++ b/contains-duplicate/heypaprika.py @@ -0,0 +1,10 @@ +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + num_dict = {} + for num in nums: + if num in num_dict: + return True + else: + num_dict[num] = 1 + return False + From fbe1ac8ba8534b308beae57106cc8eba540765b8 Mon Sep 17 00:00:00 2001 From: Changhyun Lee Date: Mon, 9 Dec 2024 11:43:16 +0900 Subject: [PATCH 2/5] ADD : #220 #237 #240 #264 by heypaprika --- house-robber/heypaprika.py | 18 ++++++++++++++++++ longest-consecutive-sequence/heypaprika.py | 21 +++++++++++++++++++++ top-k-frequent-elements/heypaprika.py | 15 +++++++++++++++ valid-palindrome/heypaprika.py | 14 ++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 house-robber/heypaprika.py create mode 100644 longest-consecutive-sequence/heypaprika.py create mode 100644 top-k-frequent-elements/heypaprika.py create mode 100644 valid-palindrome/heypaprika.py diff --git a/house-robber/heypaprika.py b/house-robber/heypaprika.py new file mode 100644 index 000000000..583399a1e --- /dev/null +++ b/house-robber/heypaprika.py @@ -0,0 +1,18 @@ +class Solution: + def rob(self, nums: List[int]) -> int: + a = [0] * len(nums) + + if len(nums) == 1: + return nums[0] + elif len(nums) == 2: + return max(nums[0], nums[1]) + + a[0] = nums[0] + a[1] = nums[1] + a[2] = max(a[0] + nums[2], a[1]) + + for i in range(3, len(nums)): + a[i] = max(a[i-3], a[i-2]) + nums[i] + + return max(a) + diff --git a/longest-consecutive-sequence/heypaprika.py b/longest-consecutive-sequence/heypaprika.py new file mode 100644 index 000000000..a1f618d9a --- /dev/null +++ b/longest-consecutive-sequence/heypaprika.py @@ -0,0 +1,21 @@ +class Solution: + def longestConsecutive(self, nums: List[int]) -> int: + nums = sorted(list(set(nums))) + if len(nums) == 0: + return 0 + elif len(nums) == 1: + return 1 + cur_long = 1 + longest = 1 + for i, num in enumerate(nums): + if i == 0: + continue + else: + if nums[i-1] + 1 == nums[i]: + cur_long += 1 + if longest < cur_long: + longest = cur_long + else: + cur_long = 1 + return longest + diff --git a/top-k-frequent-elements/heypaprika.py b/top-k-frequent-elements/heypaprika.py new file mode 100644 index 000000000..bfd5996a8 --- /dev/null +++ b/top-k-frequent-elements/heypaprika.py @@ -0,0 +1,15 @@ +import heapq +class Solution: + def topKFrequent(self, nums: List[int], k: int) -> List[int]: + + num_dict = {} + for num in nums: + num_dict[num] = num_dict.get(num, 0) + 1 + heap = [] + for k_, v in num_dict.items(): + heapq.heappush(heap, [-v, k_]) + ans = [] + for i in range(k): + ans.append(heapq.heappop(heap)[1]) + return ans + diff --git a/valid-palindrome/heypaprika.py b/valid-palindrome/heypaprika.py new file mode 100644 index 000000000..41272ff9d --- /dev/null +++ b/valid-palindrome/heypaprika.py @@ -0,0 +1,14 @@ +class Solution: + def isPalindrome(self, s: str) -> bool: + s = "".join(s.lower().split(" ")) + new_s = "" + for item in s: + if (ord("a") <= ord(item) <= ord("z")) or (ord("0") <= ord(item) <= ord("9")): + new_s += item + output = True + for i in range(len(new_s) // 2): + if new_s[i] != new_s[-i-1]: + output = False + break + return output + From 9eda1834ec6bc541b8723025d03c9c2f6e67718a Mon Sep 17 00:00:00 2001 From: Changhyun Lee Date: Tue, 10 Dec 2024 16:16:59 +0900 Subject: [PATCH 3/5] EDIT : Big-O --- contains-duplicate/heypaprika.py | 1 + house-robber/heypaprika.py | 1 + longest-consecutive-sequence/heypaprika.py | 1 + top-k-frequent-elements/heypaprika.py | 1 + valid-palindrome/heypaprika.py | 1 + 5 files changed, 5 insertions(+) diff --git a/contains-duplicate/heypaprika.py b/contains-duplicate/heypaprika.py index 2aa679a9b..dfa6d3123 100644 --- a/contains-duplicate/heypaprika.py +++ b/contains-duplicate/heypaprika.py @@ -1,3 +1,4 @@ +# Big-O 예상 : O(n*k) class Solution: def containsDuplicate(self, nums: List[int]) -> bool: num_dict = {} diff --git a/house-robber/heypaprika.py b/house-robber/heypaprika.py index 583399a1e..c62cbf0ec 100644 --- a/house-robber/heypaprika.py +++ b/house-robber/heypaprika.py @@ -1,3 +1,4 @@ +# Big-O 예상 : O(n) class Solution: def rob(self, nums: List[int]) -> int: a = [0] * len(nums) diff --git a/longest-consecutive-sequence/heypaprika.py b/longest-consecutive-sequence/heypaprika.py index a1f618d9a..6122ea730 100644 --- a/longest-consecutive-sequence/heypaprika.py +++ b/longest-consecutive-sequence/heypaprika.py @@ -1,3 +1,4 @@ +# Big-O 예상 : O(nlog(n)) class Solution: def longestConsecutive(self, nums: List[int]) -> int: nums = sorted(list(set(nums))) diff --git a/top-k-frequent-elements/heypaprika.py b/top-k-frequent-elements/heypaprika.py index bfd5996a8..c440d1f86 100644 --- a/top-k-frequent-elements/heypaprika.py +++ b/top-k-frequent-elements/heypaprika.py @@ -1,3 +1,4 @@ +# Big-O 예상 : O(nlog(n)) import heapq class Solution: def topKFrequent(self, nums: List[int], k: int) -> List[int]: diff --git a/valid-palindrome/heypaprika.py b/valid-palindrome/heypaprika.py index 41272ff9d..58463d55f 100644 --- a/valid-palindrome/heypaprika.py +++ b/valid-palindrome/heypaprika.py @@ -1,3 +1,4 @@ +# Big-O 예상 : O(n) class Solution: def isPalindrome(self, s: str) -> bool: s = "".join(s.lower().split(" ")) From 499d34ab24968da2d6f60d7f2376a4f4beafe063 Mon Sep 17 00:00:00 2001 From: ChangHyun Lee <34360681+heypaprika@users.noreply.github.com> Date: Thu, 12 Dec 2024 10:33:02 +0900 Subject: [PATCH 4/5] Update valid-palindrome/heypaprika.py Co-authored-by: moonhyeok song --- valid-palindrome/heypaprika.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/valid-palindrome/heypaprika.py b/valid-palindrome/heypaprika.py index 58463d55f..64b03e9bd 100644 --- a/valid-palindrome/heypaprika.py +++ b/valid-palindrome/heypaprika.py @@ -7,9 +7,7 @@ def isPalindrome(self, s: str) -> bool: if (ord("a") <= ord(item) <= ord("z")) or (ord("0") <= ord(item) <= ord("9")): new_s += item output = True - for i in range(len(new_s) // 2): - if new_s[i] != new_s[-i-1]: - output = False - break + new_s_2 = new_s[::-1] + return new_s_2 == new_s return output From fb3980df3abef3d81ed2dd61ebe788dc6b83b3c2 Mon Sep 17 00:00:00 2001 From: Changhyun Lee Date: Thu, 12 Dec 2024 10:36:04 +0900 Subject: [PATCH 5/5] EDIT : contains-duplicate Big-O prediction --- contains-duplicate/heypaprika.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contains-duplicate/heypaprika.py b/contains-duplicate/heypaprika.py index dfa6d3123..e2dd01bc8 100644 --- a/contains-duplicate/heypaprika.py +++ b/contains-duplicate/heypaprika.py @@ -1,4 +1,4 @@ -# Big-O 예상 : O(n*k) +# Big-O 예상 : O(n) class Solution: def containsDuplicate(self, nums: List[int]) -> bool: num_dict = {}