From 6a4b03862ec502e4e5591afac73fc2dc5853dc48 Mon Sep 17 00:00:00 2001 From: E-1on Date: Sat, 19 Apr 2025 22:06:55 +0900 Subject: [PATCH 1/2] =?UTF-8?q?3=EC=A3=BC=EC=B0=A8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- combination-sum/Sung-Heon.py | 20 ++++++++++++++++++++ decode-ways/Sung-Heon.py | 19 +++++++++++++++++++ maximum-subarray/Sung-Heon.py | 10 ++++++++++ number-of-1-bits/Sung-Heon.py | 7 +++++++ valid-palindrome/Sung-Heon.py | 24 ++++++++++++++++++++++++ 5 files changed, 80 insertions(+) create mode 100644 combination-sum/Sung-Heon.py create mode 100644 decode-ways/Sung-Heon.py create mode 100644 maximum-subarray/Sung-Heon.py create mode 100644 number-of-1-bits/Sung-Heon.py create mode 100644 valid-palindrome/Sung-Heon.py diff --git a/combination-sum/Sung-Heon.py b/combination-sum/Sung-Heon.py new file mode 100644 index 000000000..55ce74d72 --- /dev/null +++ b/combination-sum/Sung-Heon.py @@ -0,0 +1,20 @@ +class Solution: + def combinationSum(self, candidates: list[int], target: int) -> list[list[int]]: + result = [] + + def backtrack(start: int, target: int, current: list[int]): + if target == 0: + result.append(current[:]) + return + + for i in range(start, len(candidates)): + if candidates[i] > target: + continue + + current.append(candidates[i]) + backtrack(i, target - candidates[i], current) + current.pop() + + candidates.sort() + backtrack(0, target, []) + return result diff --git a/decode-ways/Sung-Heon.py b/decode-ways/Sung-Heon.py new file mode 100644 index 000000000..77ee5452d --- /dev/null +++ b/decode-ways/Sung-Heon.py @@ -0,0 +1,19 @@ +class Solution: + def numDecodings(self, s: str) -> int: + if not s or s[0] == '0': + return 0 + + n = len(s) + dp = [0] * (n + 1) + dp[0] = 1 + dp[1] = 1 + + for i in range(2, n + 1): + if s[i - 1] != '0': + dp[i] += dp[i - 1] + + two_digit = int(s[i - 2:i]) + if 10 <= two_digit <= 26: + dp[i] += dp[i - 2] + + return dp[n] \ No newline at end of file diff --git a/maximum-subarray/Sung-Heon.py b/maximum-subarray/Sung-Heon.py new file mode 100644 index 000000000..10e3da33f --- /dev/null +++ b/maximum-subarray/Sung-Heon.py @@ -0,0 +1,10 @@ +class Solution: + def maxSubArray(self, nums: list[int]) -> int: + max_sum = nums[0] + current_sum = nums[0] + + for num in nums[1:]: + current_sum = max(num, current_sum + num) + max_sum = max(max_sum, current_sum) + + return max_sum diff --git a/number-of-1-bits/Sung-Heon.py b/number-of-1-bits/Sung-Heon.py new file mode 100644 index 000000000..089d10d73 --- /dev/null +++ b/number-of-1-bits/Sung-Heon.py @@ -0,0 +1,7 @@ +class Solution: + def hammingWeight(self, n: int) -> int: + count = 0 + while n: + count += n & 1 + n >>= 1 + return count diff --git a/valid-palindrome/Sung-Heon.py b/valid-palindrome/Sung-Heon.py new file mode 100644 index 000000000..6e199c767 --- /dev/null +++ b/valid-palindrome/Sung-Heon.py @@ -0,0 +1,24 @@ +class Solution: + def isPalindrome(self, s: str) -> bool: + filtered = ''.join(char.lower() for char in s if char.isalnum()) + end = len(filtered) - 1 + if end <= 0: + return True + start = 0 + while True: + end_s = filtered[end] + start_s = filtered[start] + if end_s == start_s: + end -= 1 + start += 1 + + + else: + return False + if start >= end: + return True + if end <= 0: + return True + continue + + From aa8c514611993cbb4ab126c5d1f0edfe7a4dbf3a Mon Sep 17 00:00:00 2001 From: Sung-Heon Date: Sat, 19 Apr 2025 22:10:46 +0900 Subject: [PATCH 2/2] =?UTF-8?q?3=EC=A3=BC=EC=B0=A8.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- decode-ways/Sung-Heon.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decode-ways/Sung-Heon.py b/decode-ways/Sung-Heon.py index 77ee5452d..bcbb8e495 100644 --- a/decode-ways/Sung-Heon.py +++ b/decode-ways/Sung-Heon.py @@ -16,4 +16,4 @@ def numDecodings(self, s: str) -> int: if 10 <= two_digit <= 26: dp[i] += dp[i - 2] - return dp[n] \ No newline at end of file + return dp[n]