From 7863575417ec4f29f07e5fa9330e71d19edd686d Mon Sep 17 00:00:00 2001 From: yayyz Date: Mon, 31 Mar 2025 23:34:19 +0900 Subject: [PATCH 01/11] two sum solution --- two-sum/yayyz.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 two-sum/yayyz.py diff --git a/two-sum/yayyz.py b/two-sum/yayyz.py new file mode 100644 index 000000000..be977b509 --- /dev/null +++ b/two-sum/yayyz.py @@ -0,0 +1,8 @@ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + hashmap = {} + for i, num in enumerate(nums): + complement = target - num + if complement in hashmap: + return [hashmap[complement], i] + hashmap[num] = i \ No newline at end of file From 491461968cb99c15503e3182b3713ca544724cac Mon Sep 17 00:00:00 2001 From: yayyz Date: Mon, 31 Mar 2025 23:42:44 +0900 Subject: [PATCH 02/11] added newline --- two-sum/yayyz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/two-sum/yayyz.py b/two-sum/yayyz.py index be977b509..9e34ab112 100644 --- a/two-sum/yayyz.py +++ b/two-sum/yayyz.py @@ -5,4 +5,4 @@ def twoSum(self, nums: List[int], target: int) -> List[int]: complement = target - num if complement in hashmap: return [hashmap[complement], i] - hashmap[num] = i \ No newline at end of file + hashmap[num] = i From 0a89e70fd4b0b4b3a55a12f223bb2b4800c6982b Mon Sep 17 00:00:00 2001 From: yayyz Date: Mon, 31 Mar 2025 23:53:20 +0900 Subject: [PATCH 03/11] contains duplicate solution --- contains-duplicate/yayyz.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 contains-duplicate/yayyz.py diff --git a/contains-duplicate/yayyz.py b/contains-duplicate/yayyz.py new file mode 100644 index 000000000..9beb928f4 --- /dev/null +++ b/contains-duplicate/yayyz.py @@ -0,0 +1,4 @@ +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + + return len(nums) != len(set(nums)) \ No newline at end of file From c79c6927ad1175d45c1ee61f749adfd544081cd1 Mon Sep 17 00:00:00 2001 From: yayyz Date: Mon, 31 Mar 2025 23:54:30 +0900 Subject: [PATCH 04/11] added newline --- contains-duplicate/yayyz.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contains-duplicate/yayyz.py b/contains-duplicate/yayyz.py index 9beb928f4..c56bbd270 100644 --- a/contains-duplicate/yayyz.py +++ b/contains-duplicate/yayyz.py @@ -1,4 +1,4 @@ class Solution: def containsDuplicate(self, nums: List[int]) -> bool: - return len(nums) != len(set(nums)) \ No newline at end of file + return len(nums) != len(set(nums)) From ef71c9faf3b464270489e27c455eae655522c956 Mon Sep 17 00:00:00 2001 From: yayyz Date: Sat, 5 Apr 2025 15:38:36 +0900 Subject: [PATCH 05/11] product of array except self solution --- product-of-array-except-self/yayyz.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 product-of-array-except-self/yayyz.py diff --git a/product-of-array-except-self/yayyz.py b/product-of-array-except-self/yayyz.py new file mode 100644 index 000000000..342794a8d --- /dev/null +++ b/product-of-array-except-self/yayyz.py @@ -0,0 +1,16 @@ +class Solution: + # prefix, postfix probelm :( + def productExceptSelf(self, nums: List[int]) -> List[int]: + output = [1] * len(nums) + + prefix = 1 + for i in range(len(nums)): + output[i] = prefix + prefix *= nums[i] + + postfix = 1 + for i in range(len(nums) -1, -1, -1): + output[i] *= postfix + postfix *= nums[i] + + return output \ No newline at end of file From 1de52da7a5cec4fc3fc8672a9613be9e4df57cfe Mon Sep 17 00:00:00 2001 From: yayyz Date: Sat, 5 Apr 2025 15:41:45 +0900 Subject: [PATCH 06/11] longest consecutive sequence solution & added newline --- longest-consecutive-sequence/yayyz.py | 22 ++++++++++++++++++++++ product-of-array-except-self/yayyz.py | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 longest-consecutive-sequence/yayyz.py diff --git a/longest-consecutive-sequence/yayyz.py b/longest-consecutive-sequence/yayyz.py new file mode 100644 index 000000000..0e26235c6 --- /dev/null +++ b/longest-consecutive-sequence/yayyz.py @@ -0,0 +1,22 @@ +class Solution: + def longestConsecutive(self, nums: List[int]) -> int: + if len(nums) == 0: + return 0 + + nums = sorted(set(nums)) + + currLength = 1 + lastNum = nums[0] + result = 1 + + for i in range(1, len(nums)): + if nums[i] == lastNum + 1: + currLength += 1 + else: + currLength = 1 + + result = max(result, currLength) + lastNum = nums[i] + + return result + \ No newline at end of file diff --git a/product-of-array-except-self/yayyz.py b/product-of-array-except-self/yayyz.py index 342794a8d..592205be6 100644 --- a/product-of-array-except-self/yayyz.py +++ b/product-of-array-except-self/yayyz.py @@ -13,4 +13,5 @@ def productExceptSelf(self, nums: List[int]) -> List[int]: output[i] *= postfix postfix *= nums[i] - return output \ No newline at end of file + return output + \ No newline at end of file From b74f6ce2d3735ea3b4a23302e3a9383644ab5158 Mon Sep 17 00:00:00 2001 From: yayyz Date: Sat, 5 Apr 2025 16:52:10 +0900 Subject: [PATCH 07/11] house robber solution & added newline --- house-robber/yayyz.py | 17 +++++++++++++++++ longest-consecutive-sequence/yayyz.py | 2 ++ 2 files changed, 19 insertions(+) create mode 100644 house-robber/yayyz.py diff --git a/house-robber/yayyz.py b/house-robber/yayyz.py new file mode 100644 index 000000000..bccb32a88 --- /dev/null +++ b/house-robber/yayyz.py @@ -0,0 +1,17 @@ +class Solution: + def rob(self, nums: List[int]) -> int: + n = len(nums) + + if n == 1: + return nums[0] + + dp = [0] * n + dp[0] = nums[0] + dp[1] = max(nums[0], nums[1]) + + # i 번째를 털지 않은 조건과 i번째를 털은 조건 중 max를 비교 + for i in range(2, n): + dp[i] = max(dp[i-1], dp[i-2] + nums[i]) + + return dp[-1] + \ No newline at end of file diff --git a/longest-consecutive-sequence/yayyz.py b/longest-consecutive-sequence/yayyz.py index 0e26235c6..bde80f34f 100644 --- a/longest-consecutive-sequence/yayyz.py +++ b/longest-consecutive-sequence/yayyz.py @@ -19,4 +19,6 @@ def longestConsecutive(self, nums: List[int]) -> int: lastNum = nums[i] return result + + \ No newline at end of file From 9b163e2fa9a2aedae69c4a82e9ad99e7d3570a40 Mon Sep 17 00:00:00 2001 From: yayyz Date: Sat, 5 Apr 2025 16:56:12 +0900 Subject: [PATCH 08/11] added newline --- house-robber/yayyz.py | 1 + longest-consecutive-sequence/yayyz.py | 2 +- product-of-array-except-self/yayyz.py | 2 ++ two-sum/yayyz.py | 2 ++ 4 files changed, 6 insertions(+), 1 deletion(-) diff --git a/house-robber/yayyz.py b/house-robber/yayyz.py index bccb32a88..18d20eaf7 100644 --- a/house-robber/yayyz.py +++ b/house-robber/yayyz.py @@ -14,4 +14,5 @@ def rob(self, nums: List[int]) -> int: dp[i] = max(dp[i-1], dp[i-2] + nums[i]) return dp[-1] + \ No newline at end of file diff --git a/longest-consecutive-sequence/yayyz.py b/longest-consecutive-sequence/yayyz.py index bde80f34f..ada26a5c5 100644 --- a/longest-consecutive-sequence/yayyz.py +++ b/longest-consecutive-sequence/yayyz.py @@ -19,6 +19,6 @@ def longestConsecutive(self, nums: List[int]) -> int: lastNum = nums[i] return result - + \ No newline at end of file diff --git a/product-of-array-except-self/yayyz.py b/product-of-array-except-self/yayyz.py index 592205be6..bd0ebb130 100644 --- a/product-of-array-except-self/yayyz.py +++ b/product-of-array-except-self/yayyz.py @@ -14,4 +14,6 @@ def productExceptSelf(self, nums: List[int]) -> List[int]: postfix *= nums[i] return output + + \ No newline at end of file diff --git a/two-sum/yayyz.py b/two-sum/yayyz.py index 9e34ab112..c62b495cc 100644 --- a/two-sum/yayyz.py +++ b/two-sum/yayyz.py @@ -6,3 +6,5 @@ def twoSum(self, nums: List[int], target: int) -> List[int]: if complement in hashmap: return [hashmap[complement], i] hashmap[num] = i + + From 4a6c7170f74eb5f06ae94d417b9e8fd7041eb85e Mon Sep 17 00:00:00 2001 From: yayyz Date: Sat, 5 Apr 2025 17:00:00 +0900 Subject: [PATCH 09/11] added newline --- house-robber/yayyz.py | 1 + longest-consecutive-sequence/yayyz.py | 1 + product-of-array-except-self/yayyz.py | 1 + 3 files changed, 3 insertions(+) diff --git a/house-robber/yayyz.py b/house-robber/yayyz.py index 18d20eaf7..06ba04374 100644 --- a/house-robber/yayyz.py +++ b/house-robber/yayyz.py @@ -15,4 +15,5 @@ def rob(self, nums: List[int]) -> int: return dp[-1] + \ No newline at end of file diff --git a/longest-consecutive-sequence/yayyz.py b/longest-consecutive-sequence/yayyz.py index ada26a5c5..9da810617 100644 --- a/longest-consecutive-sequence/yayyz.py +++ b/longest-consecutive-sequence/yayyz.py @@ -20,5 +20,6 @@ def longestConsecutive(self, nums: List[int]) -> int: return result + \ No newline at end of file diff --git a/product-of-array-except-self/yayyz.py b/product-of-array-except-self/yayyz.py index bd0ebb130..00c2621aa 100644 --- a/product-of-array-except-self/yayyz.py +++ b/product-of-array-except-self/yayyz.py @@ -16,4 +16,5 @@ def productExceptSelf(self, nums: List[int]) -> List[int]: return output + \ No newline at end of file From a234b584a7053c5d1be62d2df75b1dc8b0c5c979 Mon Sep 17 00:00:00 2001 From: yayyz Date: Sat, 5 Apr 2025 17:05:31 +0900 Subject: [PATCH 10/11] :rotating_light: added newline --- house-robber/yayyz.py | 4 +--- longest-consecutive-sequence/yayyz.py | 4 +--- product-of-array-except-self/yayyz.py | 3 +-- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/house-robber/yayyz.py b/house-robber/yayyz.py index 06ba04374..9b65e3359 100644 --- a/house-robber/yayyz.py +++ b/house-robber/yayyz.py @@ -14,6 +14,4 @@ def rob(self, nums: List[int]) -> int: dp[i] = max(dp[i-1], dp[i-2] + nums[i]) return dp[-1] - - - \ No newline at end of file + \ No newline at end of file diff --git a/longest-consecutive-sequence/yayyz.py b/longest-consecutive-sequence/yayyz.py index 9da810617..631355814 100644 --- a/longest-consecutive-sequence/yayyz.py +++ b/longest-consecutive-sequence/yayyz.py @@ -18,8 +18,6 @@ def longestConsecutive(self, nums: List[int]) -> int: result = max(result, currLength) lastNum = nums[i] - return result - - + return result \ No newline at end of file diff --git a/product-of-array-except-self/yayyz.py b/product-of-array-except-self/yayyz.py index 00c2621aa..e0ec5b5ea 100644 --- a/product-of-array-except-self/yayyz.py +++ b/product-of-array-except-self/yayyz.py @@ -14,7 +14,6 @@ def productExceptSelf(self, nums: List[int]) -> List[int]: postfix *= nums[i] return output - - + \ No newline at end of file From 9475b059bdcc5a3c4a597f0f5d6d1b5607cd568e Mon Sep 17 00:00:00 2001 From: yayyz Date: Sat, 5 Apr 2025 17:09:21 +0900 Subject: [PATCH 11/11] :rotating_light: added new line --- house-robber/yayyz.py | 1 - longest-consecutive-sequence/yayyz.py | 2 -- product-of-array-except-self/yayyz.py | 3 --- 3 files changed, 6 deletions(-) diff --git a/house-robber/yayyz.py b/house-robber/yayyz.py index 9b65e3359..2dc384d68 100644 --- a/house-robber/yayyz.py +++ b/house-robber/yayyz.py @@ -14,4 +14,3 @@ def rob(self, nums: List[int]) -> int: dp[i] = max(dp[i-1], dp[i-2] + nums[i]) return dp[-1] - \ No newline at end of file diff --git a/longest-consecutive-sequence/yayyz.py b/longest-consecutive-sequence/yayyz.py index 631355814..f6589a471 100644 --- a/longest-consecutive-sequence/yayyz.py +++ b/longest-consecutive-sequence/yayyz.py @@ -19,5 +19,3 @@ def longestConsecutive(self, nums: List[int]) -> int: lastNum = nums[i] return result - - \ No newline at end of file diff --git a/product-of-array-except-self/yayyz.py b/product-of-array-except-self/yayyz.py index e0ec5b5ea..e7baf402e 100644 --- a/product-of-array-except-self/yayyz.py +++ b/product-of-array-except-self/yayyz.py @@ -14,6 +14,3 @@ def productExceptSelf(self, nums: List[int]) -> List[int]: postfix *= nums[i] return output - - - \ No newline at end of file