From 8acdf4b33fd483ed7c7ad0c28fca0e66441ff2b9 Mon Sep 17 00:00:00 2001 From: doh6077 Date: Fri, 14 Nov 2025 19:18:28 -0500 Subject: [PATCH 1/3] Top K Frequent Elements solution --- top-k-frequent-elements/doh6077.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 top-k-frequent-elements/doh6077.py diff --git a/top-k-frequent-elements/doh6077.py b/top-k-frequent-elements/doh6077.py new file mode 100644 index 0000000000..d5d1d11a6a --- /dev/null +++ b/top-k-frequent-elements/doh6077.py @@ -0,0 +1,12 @@ +class Solution: + # dictionary use + def topKFrequent(self, nums: List[int], k: int) -> List[int]: + result = {} # key: 원소, value: 등장 횟수 + for n in nums: + if n in result: + result[n] = result[n] + 1 + else: + result[n] = 1 + + # 가장 자주 등장한 원소 k개 반환 + return sorted(result.keys(), key=lambda x: result[x], reverse=True)[:k] From 4aa739c525e53f69924afbc2eaf7b1dee5672476 Mon Sep 17 00:00:00 2001 From: doh6077 Date: Fri, 21 Nov 2025 14:59:07 -0500 Subject: [PATCH 2/3] 3Sum Solution --- 3sum/doh6077.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 3sum/doh6077.py diff --git a/3sum/doh6077.py b/3sum/doh6077.py new file mode 100644 index 0000000000..44b2d4435c --- /dev/null +++ b/3sum/doh6077.py @@ -0,0 +1,42 @@ +from typing import List + +class Solution: + def threeSum(self, nums: List[int]) -> List[List[int]]: + nums.sort() + n = len(nums) + res: List[List[int]] = [] + + for i in range(n - 2): + # i 중복 스킵 + if i > 0 and nums[i] == nums[i - 1]: + continue + + # nums[i] 이후는 전부 양수 → 더 이상 0 못 만듦 + if nums[i] > 0: + break + + left, right = i + 1, n - 1 + + while left < right: + total = nums[i] + nums[left] + nums[right] + + if total == 0: + res.append([nums[i], nums[left], nums[right]]) + + left += 1 + right -= 1 + + # left 중복 스킵 + while left < right and nums[left] == nums[left - 1]: + left += 1 + + # right 중복 스킵 + while left < right and nums[right] == nums[right + 1]: + right -= 1 + + elif total < 0: + left += 1 + else: + right -= 1 + + return res From fe26eb0cb575ff5cd1fac88b8ee5203ff805ede4 Mon Sep 17 00:00:00 2001 From: doh6077 Date: Fri, 21 Nov 2025 16:52:54 -0500 Subject: [PATCH 3/3] Validate Binary Search Tree Solution --- validate-binary-search-tree/doh6077.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 validate-binary-search-tree/doh6077.py diff --git a/validate-binary-search-tree/doh6077.py b/validate-binary-search-tree/doh6077.py new file mode 100644 index 0000000000..2d3288d202 --- /dev/null +++ b/validate-binary-search-tree/doh6077.py @@ -0,0 +1,10 @@ +class Solution: + def isValidBST(self, root: Optional[TreeNode]) -> bool: + def validate(node: Optional[TreeNode], low: float, high: float) -> bool: + if not node: + return True + if not (low < node.val < high): + return False + return (validate(node.left, low, node.val) and + validate(node.right, node.val, high)) + return validate(root, float('-inf'), float('inf'))