From 865ed8deb5198d5f8c8038db9754dfc4d5ae77f9 Mon Sep 17 00:00:00 2001 From: freemjstudio Date: Mon, 22 Jun 2026 01:07:05 +0900 Subject: [PATCH 01/18] freemjstudio/two-sum --- two-sum/freemjstudio.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 two-sum/freemjstudio.py diff --git a/two-sum/freemjstudio.py b/two-sum/freemjstudio.py new file mode 100644 index 0000000000..c36de0f08d --- /dev/null +++ b/two-sum/freemjstudio.py @@ -0,0 +1,13 @@ +class Solution: + def twoSum(self, nums: List[int], target: int) -> List[int]: + answer = [] + hashmap = dict() + for i in range(len(nums)): + current_num = nums[i] + diff = target - current_num + if diff in hashmap.keys(): + return [i, hashmap[diff]] + hashmap[current_num] = i # store the index of current num + + return answer + \ No newline at end of file From 1a6de375f2d596b02d7c08c3584c2e389f7a326a Mon Sep 17 00:00:00 2001 From: freemjstudio Date: Sat, 27 Jun 2026 16:38:18 +0900 Subject: [PATCH 02/18] freemjstudio: contains-duplicate (easy, python) --- contains-duplicate/freemjstudio.py | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 contains-duplicate/freemjstudio.py diff --git a/contains-duplicate/freemjstudio.py b/contains-duplicate/freemjstudio.py new file mode 100644 index 0000000000..bee8ade7ad --- /dev/null +++ b/contains-duplicate/freemjstudio.py @@ -0,0 +1,6 @@ +class Solution: + def containsDuplicate(self, nums: List[int]) -> bool: + first = len(nums) + set_nums = set(nums) + second = len(set_nums) + return (first != second) \ No newline at end of file From 953117650d0c3fc4c75ccd15503f14b75bc43cde Mon Sep 17 00:00:00 2001 From: freemjstudio Date: Sat, 27 Jun 2026 16:38:42 +0900 Subject: [PATCH 03/18] freemjstudio: contains-duplicate --- contains-duplicate/freemjstudio.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/contains-duplicate/freemjstudio.py b/contains-duplicate/freemjstudio.py index bee8ade7ad..0273cbd4e3 100644 --- a/contains-duplicate/freemjstudio.py +++ b/contains-duplicate/freemjstudio.py @@ -1,6 +1,8 @@ class Solution: def containsDuplicate(self, nums: List[int]) -> bool: - first = len(nums) - set_nums = set(nums) + first = len(nums) # O(1) : 리스트 객체는 이미 자기자신의 길이를 저장하고 있음 + set_nums = set(nums) # O(N) second = len(set_nums) - return (first != second) \ No newline at end of file + return (first != second) + +# 시간 복잡도 : O(N) \ No newline at end of file From 370fe38dead4945f03001ca6800b1e397359f5fc Mon Sep 17 00:00:00 2001 From: freemjstudio Date: Sun, 28 Jun 2026 15:38:37 +0900 Subject: [PATCH 04/18] freemjstudio: top k frequent elements --- top-k-frequent-elements/freemjstudio.py | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 top-k-frequent-elements/freemjstudio.py diff --git a/top-k-frequent-elements/freemjstudio.py b/top-k-frequent-elements/freemjstudio.py new file mode 100644 index 0000000000..184c87aeee --- /dev/null +++ b/top-k-frequent-elements/freemjstudio.py @@ -0,0 +1,29 @@ +import heapq + +class Solution: + def topKFrequent(self, nums: List[int], k: int) -> List[int]: + answer = [] + count = dict() + heap = [] + if len(nums) <= 1: + return nums + # O(N) + for num in nums: + count[num] = count.get(num, 0) + 1 + + # heap 의 크기는 최대 k 로 제한함. + # unique 한 M개의 숫자를 선형 순회 O(M) + for num, freq in count.items(): + if len(heap) < k: + heapq.heappush(heap, (freq, num)) # O(logK) + else: + if heap[0][0] < freq: + heapq.heappop(heap) # O(logK) + heapq.heappush(heap, (freq, num)) # O(logK) + + for _ in range(k): + k, v = heapq.heappop(heap) + answer.append(v) + + return answer + From db69654f98e5b21d05356c77480071fcc2fc747c Mon Sep 17 00:00:00 2001 From: freemjstudio Date: Thu, 2 Jul 2026 00:42:35 +0900 Subject: [PATCH 05/18] =?UTF-8?q?liner=20=EC=A0=81=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- contains-duplicate/freemjstudio.py | 2 +- two-sum/freemjstudio.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/contains-duplicate/freemjstudio.py b/contains-duplicate/freemjstudio.py index 0273cbd4e3..6048a3c5ea 100644 --- a/contains-duplicate/freemjstudio.py +++ b/contains-duplicate/freemjstudio.py @@ -5,4 +5,4 @@ def containsDuplicate(self, nums: List[int]) -> bool: second = len(set_nums) return (first != second) -# 시간 복잡도 : O(N) \ No newline at end of file +# 시간 복잡도 : O(N) diff --git a/two-sum/freemjstudio.py b/two-sum/freemjstudio.py index c36de0f08d..a274028f5c 100644 --- a/two-sum/freemjstudio.py +++ b/two-sum/freemjstudio.py @@ -10,4 +10,3 @@ def twoSum(self, nums: List[int], target: int) -> List[int]: hashmap[current_num] = i # store the index of current num return answer - \ No newline at end of file From 4886e4ae81c553204d4fb777bee15d6f2e656ac8 Mon Sep 17 00:00:00 2001 From: freemjstudio Date: Sat, 4 Jul 2026 13:36:49 +0900 Subject: [PATCH 06/18] freemjstudio/3sum --- 3sum/freemjstudio.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 3sum/freemjstudio.py diff --git a/3sum/freemjstudio.py b/3sum/freemjstudio.py new file mode 100644 index 0000000000..546a726a1a --- /dev/null +++ b/3sum/freemjstudio.py @@ -0,0 +1,29 @@ +class Solution: + def threeSum(self, nums: list[int]) -> list[list[int]]: + answer = [] + nums.sort() + + for i in range(len(nums)): + # 중복된 원소가 있는 경우 똑같이 검사할 필요가 없으므로 건너뛴다. + if i > 0 and nums[i] == nums[i-1]: + continue + + left, right = i+1, len(nums) - 1 + + while left < right: + total = nums[i] + nums[left] + nums[right] + if total == 0: + answer.append([nums[i], nums[left], nums[right]]) + # left, right 포인터를 둘다 한칸씩 이동시켜 다음 조합을 검사한다. + left += 1 + right -= 1 + + # 중복된 원소가 있는 경우 같은 정답 조합을 방지한다 + while left < right and nums[left] == nums[left -1]: + left += 1 + + elif total < 0: + left += 1 + else: + right -= 1 + return answer \ No newline at end of file From 2f3e189469125e7364ca761dab3ca351f680af2d Mon Sep 17 00:00:00 2001 From: freemjstudio Date: Sat, 4 Jul 2026 16:28:00 +0900 Subject: [PATCH 07/18] freemjstudio/climbing-stairs --- climbing-stairs/freemjstudio.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 climbing-stairs/freemjstudio.py diff --git a/climbing-stairs/freemjstudio.py b/climbing-stairs/freemjstudio.py new file mode 100644 index 0000000000..d0eb35cb40 --- /dev/null +++ b/climbing-stairs/freemjstudio.py @@ -0,0 +1,18 @@ +class Solution: + def climbStairs(self, n: int) -> int: + answer = 0 + if n == 1: # ways(1) = 1 + return 1 + + if n == 2: # ways(2) = 2 + return 2 + + dp = [0] * 46 # 1 <= n <= 45 + dp[1] = 1 + dp[2] = 2 + + # 점화식 : ways(n) = ways(n-1) + ways(n-2) + for i in range(3, n+1): + dp[i] = dp[i-1] + dp[i-2] + return dp[n] + \ No newline at end of file From 4c68b30f26cdc62100ba69972eb9f332a762c8ed Mon Sep 17 00:00:00 2001 From: freemjstudio Date: Sat, 4 Jul 2026 19:20:51 +0900 Subject: [PATCH 08/18] freemjstudio/valid anagram --- valid-anagram/freemjstudio.py | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 valid-anagram/freemjstudio.py diff --git a/valid-anagram/freemjstudio.py b/valid-anagram/freemjstudio.py new file mode 100644 index 0000000000..ff422e7ebc --- /dev/null +++ b/valid-anagram/freemjstudio.py @@ -0,0 +1,3 @@ +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + return sorted(list(s)) == sorted(list(t)) From 22f93657678b939ae627162c7b871d60b65343a4 Mon Sep 17 00:00:00 2001 From: freemjstudio Date: Sat, 4 Jul 2026 19:20:51 +0900 Subject: [PATCH 09/18] freemjstudio/valid anagram --- 3sum/freemjstudio.py | 2 +- climbing-stairs/freemjstudio.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/3sum/freemjstudio.py b/3sum/freemjstudio.py index 546a726a1a..92a6a3f66f 100644 --- a/3sum/freemjstudio.py +++ b/3sum/freemjstudio.py @@ -26,4 +26,4 @@ def threeSum(self, nums: list[int]) -> list[list[int]]: left += 1 else: right -= 1 - return answer \ No newline at end of file + return answer diff --git a/climbing-stairs/freemjstudio.py b/climbing-stairs/freemjstudio.py index d0eb35cb40..4b2e390a90 100644 --- a/climbing-stairs/freemjstudio.py +++ b/climbing-stairs/freemjstudio.py @@ -15,4 +15,3 @@ def climbStairs(self, n: int) -> int: for i in range(3, n+1): dp[i] = dp[i-1] + dp[i-2] return dp[n] - \ No newline at end of file From dae40c719c9d988d0216ee1dab275577741be5d7 Mon Sep 17 00:00:00 2001 From: freemjstudio Date: Sat, 4 Jul 2026 19:32:11 +0900 Subject: [PATCH 10/18] =?UTF-8?q?freemjstudio/valid-anagram=20=EB=91=90?= =?UTF-8?q?=EB=B2=88=EC=A7=B8=20=ED=92=80=EC=9D=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- valid-anagram/freemjstudio.py | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/valid-anagram/freemjstudio.py b/valid-anagram/freemjstudio.py index ff422e7ebc..44fa9a12ea 100644 --- a/valid-anagram/freemjstudio.py +++ b/valid-anagram/freemjstudio.py @@ -1,3 +1,32 @@ +""" +첫번째 풀이 +시간 복잡도 : O(n log n) +""" + class Solution: def isAnagram(self, s: str, t: str) -> bool: - return sorted(list(s)) == sorted(list(t)) + return sorted(s) == sorted(t) + +""" +두번째 풀이 +시간 복잡도 : O(n) +""" + +class Solution: + def isAnagram(self, s: str, t: str) -> bool: + # 반례 : s = ab, t = a + # 이 경우에는 t에 없는 b가 존재하므로 False를 반환해야 한다. + if len(s) != len(t): + return False + counter = {} + + for ch in s: + counter[ch] = counter.get(ch, 0) + 1 + + for ch in t: + if ch not in counter: + return False + counter[ch] -= 1 + if counter[ch] < 0: + return False + return True From 067afdb08b21253b02c99ab701824058cad43005 Mon Sep 17 00:00:00 2001 From: freemjstudio Date: Tue, 7 Jul 2026 01:30:57 +0900 Subject: [PATCH 11/18] add: product-of-array-except-self --- product-of-array-except-self/freemjstudio.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 product-of-array-except-self/freemjstudio.py diff --git a/product-of-array-except-self/freemjstudio.py b/product-of-array-except-self/freemjstudio.py new file mode 100644 index 0000000000..5638e08576 --- /dev/null +++ b/product-of-array-except-self/freemjstudio.py @@ -0,0 +1,17 @@ +class Solution: + def productExceptSelf(self, nums: List[int]) -> List[int]: + answer = [1] * len(nums) + + # left -> right + for i in range(1, len(nums)): + answer[i] = answer[i-1] * nums[i-1] # 왼쪽에 있는 것들을 곱하자 + + # right -> left + right_product = 1 + for i in range(len(nums)-1, -1, -1): + answer[i] = answer[i] * right_product + right_product = right_product * nums[i] + + + return answer + \ No newline at end of file From 54d8362d23f1c4434bc1527c3ee3ea2ba19cc644 Mon Sep 17 00:00:00 2001 From: freemjstudio Date: Sat, 11 Jul 2026 12:21:31 +0900 Subject: [PATCH 12/18] freemjstudio/valid-palindrome --- valid-palindrome/freemjstudio.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 valid-palindrome/freemjstudio.py diff --git a/valid-palindrome/freemjstudio.py b/valid-palindrome/freemjstudio.py new file mode 100644 index 0000000000..f0d2c1c269 --- /dev/null +++ b/valid-palindrome/freemjstudio.py @@ -0,0 +1,21 @@ +class Solution: + def isPalindrome(self, s: str) -> bool: + characters = "abcdefghijklmnopqrstuvwxyz0123456789" + s = s.lower() + + filtered = "" + for ch in s: + if ch in characters: + filtered += ch + + n = len(filtered) + left = 0 + right = n-1 + while left <= n//2 and right >= n//2: + if filtered[left] == filtered[right]: + left += 1 + right -= 1 + else: + return False + + return True \ No newline at end of file From def540d5f5de34584d661a3e1811821ce4f9fd66 Mon Sep 17 00:00:00 2001 From: freemjstudio Date: Sat, 11 Jul 2026 12:52:46 +0900 Subject: [PATCH 13/18] freemjstudio/number-of-1-bits --- number-of-1-bits/freemjstudio.py | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 number-of-1-bits/freemjstudio.py diff --git a/number-of-1-bits/freemjstudio.py b/number-of-1-bits/freemjstudio.py new file mode 100644 index 0000000000..e2821129fa --- /dev/null +++ b/number-of-1-bits/freemjstudio.py @@ -0,0 +1,4 @@ +class Solution: + def hammingWeight(self, n: int) -> int: + binary = bin(n) + return binary.count("1") From b33b7b1f7479ddc758bea25091f578fe6c540fd4 Mon Sep 17 00:00:00 2001 From: freemjstudio Date: Sat, 11 Jul 2026 12:54:17 +0900 Subject: [PATCH 14/18] freemjstudio/number-of-1-bits second solution --- number-of-1-bits/freemjstudio.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/number-of-1-bits/freemjstudio.py b/number-of-1-bits/freemjstudio.py index e2821129fa..15d44ad981 100644 --- a/number-of-1-bits/freemjstudio.py +++ b/number-of-1-bits/freemjstudio.py @@ -2,3 +2,13 @@ class Solution: def hammingWeight(self, n: int) -> int: binary = bin(n) return binary.count("1") + +class Solution: + def hammingWeight(self, n: int) -> int: + count = 0 + + while n > 0: + count += n % 2 + n //=2 + + return count \ No newline at end of file From fe69c94f926e3044db8c882eac1227f5fd21e8df Mon Sep 17 00:00:00 2001 From: freemjstudio Date: Sat, 11 Jul 2026 16:50:44 +0900 Subject: [PATCH 15/18] freemjstudio/combination-sum --- combination-sum/freemjstudio.py | 23 +++++++++++++++++++++++ number-of-1-bits/freemjstudio.py | 1 + 2 files changed, 24 insertions(+) create mode 100644 combination-sum/freemjstudio.py diff --git a/combination-sum/freemjstudio.py b/combination-sum/freemjstudio.py new file mode 100644 index 0000000000..459cb6fbfb --- /dev/null +++ b/combination-sum/freemjstudio.py @@ -0,0 +1,23 @@ +class Solution: + def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: + answer = [] + + def backtracking(start_idx, total, path): + if target == total: + answer.append(path[:]) # 새로운 리스트 객체를 만들어서 저장함. + # 리스트가 mutable 객체이므로 path[:] 로 복사하지 않으면 path 가 바뀔 때 answer 안의 값도 바뀌게 된다. + return + + if target < total: + return + + for idx in range(start_idx, len(candidates)): + new_node = candidates[idx] # 동일한 숫자 재사용 가능함. start_idx 도 포함한다. + path.append(new_node) + + backtracking(idx, total + new_node, path) + # 선택 취소 + path.pop() + + backtracking(0, 0, []) + return answer \ No newline at end of file diff --git a/number-of-1-bits/freemjstudio.py b/number-of-1-bits/freemjstudio.py index 15d44ad981..de7fd5dd3a 100644 --- a/number-of-1-bits/freemjstudio.py +++ b/number-of-1-bits/freemjstudio.py @@ -3,6 +3,7 @@ def hammingWeight(self, n: int) -> int: binary = bin(n) return binary.count("1") +# bin() 을 못쓰는 경우의 풀이 class Solution: def hammingWeight(self, n: int) -> int: count = 0 From d9759bcacce838ac652d6a9885ffce24f9660ba0 Mon Sep 17 00:00:00 2001 From: freemjstudio Date: Sat, 11 Jul 2026 16:52:27 +0900 Subject: [PATCH 16/18] Fix trailing whitespace in solutions --- 3sum/freemjstudio.py | 12 ++++++------ climbing-stairs/freemjstudio.py | 4 ++-- combination-sum/freemjstudio.py | 20 ++++++++++---------- contains-duplicate/freemjstudio.py | 2 +- number-of-1-bits/freemjstudio.py | 4 ++-- product-of-array-except-self/freemjstudio.py | 11 +++++------ top-k-frequent-elements/freemjstudio.py | 18 +++++++++--------- two-sum/freemjstudio.py | 6 +++--- valid-anagram/freemjstudio.py | 16 ++++++++-------- valid-palindrome/freemjstudio.py | 12 ++++++------ 10 files changed, 52 insertions(+), 53 deletions(-) diff --git a/3sum/freemjstudio.py b/3sum/freemjstudio.py index 92a6a3f66f..b6d16520c8 100644 --- a/3sum/freemjstudio.py +++ b/3sum/freemjstudio.py @@ -1,16 +1,16 @@ class Solution: def threeSum(self, nums: list[int]) -> list[list[int]]: answer = [] - nums.sort() - + nums.sort() + for i in range(len(nums)): # 중복된 원소가 있는 경우 똑같이 검사할 필요가 없으므로 건너뛴다. if i > 0 and nums[i] == nums[i-1]: - continue + continue left, right = i+1, len(nums) - 1 - while left < right: + while left < right: total = nums[i] + nums[left] + nums[right] if total == 0: answer.append([nums[i], nums[left], nums[right]]) @@ -18,12 +18,12 @@ def threeSum(self, nums: list[int]) -> list[list[int]]: left += 1 right -= 1 - # 중복된 원소가 있는 경우 같은 정답 조합을 방지한다 + # 중복된 원소가 있는 경우 같은 정답 조합을 방지한다 while left < right and nums[left] == nums[left -1]: left += 1 elif total < 0: left += 1 - else: + else: right -= 1 return answer diff --git a/climbing-stairs/freemjstudio.py b/climbing-stairs/freemjstudio.py index 4b2e390a90..29bc2fa9a3 100644 --- a/climbing-stairs/freemjstudio.py +++ b/climbing-stairs/freemjstudio.py @@ -1,12 +1,12 @@ class Solution: def climbStairs(self, n: int) -> int: - answer = 0 + answer = 0 if n == 1: # ways(1) = 1 return 1 if n == 2: # ways(2) = 2 return 2 - + dp = [0] * 46 # 1 <= n <= 45 dp[1] = 1 dp[2] = 2 diff --git a/combination-sum/freemjstudio.py b/combination-sum/freemjstudio.py index 459cb6fbfb..3dc8bdc42f 100644 --- a/combination-sum/freemjstudio.py +++ b/combination-sum/freemjstudio.py @@ -1,23 +1,23 @@ class Solution: def combinationSum(self, candidates: List[int], target: int) -> List[List[int]]: answer = [] - - def backtracking(start_idx, total, path): - if target == total: + + def backtracking(start_idx, total, path): + if target == total: answer.append(path[:]) # 새로운 리스트 객체를 만들어서 저장함. # 리스트가 mutable 객체이므로 path[:] 로 복사하지 않으면 path 가 바뀔 때 answer 안의 값도 바뀌게 된다. - return + return if target < total: - return + return - for idx in range(start_idx, len(candidates)): - new_node = candidates[idx] # 동일한 숫자 재사용 가능함. start_idx 도 포함한다. + for idx in range(start_idx, len(candidates)): + new_node = candidates[idx] # 동일한 숫자 재사용 가능함. start_idx 도 포함한다. path.append(new_node) - backtracking(idx, total + new_node, path) - # 선택 취소 + backtracking(idx, total + new_node, path) + # 선택 취소 path.pop() backtracking(0, 0, []) - return answer \ No newline at end of file + return answer \ No newline at end of file diff --git a/contains-duplicate/freemjstudio.py b/contains-duplicate/freemjstudio.py index 6048a3c5ea..b9cdeddb4c 100644 --- a/contains-duplicate/freemjstudio.py +++ b/contains-duplicate/freemjstudio.py @@ -1,6 +1,6 @@ class Solution: def containsDuplicate(self, nums: List[int]) -> bool: - first = len(nums) # O(1) : 리스트 객체는 이미 자기자신의 길이를 저장하고 있음 + first = len(nums) # O(1) : 리스트 객체는 이미 자기자신의 길이를 저장하고 있음 set_nums = set(nums) # O(N) second = len(set_nums) return (first != second) diff --git a/number-of-1-bits/freemjstudio.py b/number-of-1-bits/freemjstudio.py index de7fd5dd3a..9e657f790d 100644 --- a/number-of-1-bits/freemjstudio.py +++ b/number-of-1-bits/freemjstudio.py @@ -6,10 +6,10 @@ def hammingWeight(self, n: int) -> int: # bin() 을 못쓰는 경우의 풀이 class Solution: def hammingWeight(self, n: int) -> int: - count = 0 + count = 0 while n > 0: count += n % 2 n //=2 - + return count \ No newline at end of file diff --git a/product-of-array-except-self/freemjstudio.py b/product-of-array-except-self/freemjstudio.py index 5638e08576..09df575b56 100644 --- a/product-of-array-except-self/freemjstudio.py +++ b/product-of-array-except-self/freemjstudio.py @@ -1,17 +1,16 @@ class Solution: def productExceptSelf(self, nums: List[int]) -> List[int]: answer = [1] * len(nums) - - # left -> right + + # left -> right for i in range(1, len(nums)): - answer[i] = answer[i-1] * nums[i-1] # 왼쪽에 있는 것들을 곱하자 + answer[i] = answer[i-1] * nums[i-1] # 왼쪽에 있는 것들을 곱하자 # right -> left right_product = 1 for i in range(len(nums)-1, -1, -1): answer[i] = answer[i] * right_product right_product = right_product * nums[i] - - return answer - \ No newline at end of file + + return answer diff --git a/top-k-frequent-elements/freemjstudio.py b/top-k-frequent-elements/freemjstudio.py index 184c87aeee..ed8cf1c339 100644 --- a/top-k-frequent-elements/freemjstudio.py +++ b/top-k-frequent-elements/freemjstudio.py @@ -5,18 +5,18 @@ def topKFrequent(self, nums: List[int], k: int) -> List[int]: answer = [] count = dict() heap = [] - if len(nums) <= 1: + if len(nums) <= 1: return nums - # O(N) - for num in nums: + # O(N) + for num in nums: count[num] = count.get(num, 0) + 1 - - # heap 의 크기는 최대 k 로 제한함. + + # heap 의 크기는 최대 k 로 제한함. # unique 한 M개의 숫자를 선형 순회 O(M) for num, freq in count.items(): - if len(heap) < k: + if len(heap) < k: heapq.heappush(heap, (freq, num)) # O(logK) - else: + else: if heap[0][0] < freq: heapq.heappop(heap) # O(logK) heapq.heappush(heap, (freq, num)) # O(logK) @@ -25,5 +25,5 @@ def topKFrequent(self, nums: List[int], k: int) -> List[int]: k, v = heapq.heappop(heap) answer.append(v) - return answer - + return answer + diff --git a/two-sum/freemjstudio.py b/two-sum/freemjstudio.py index a274028f5c..69426fb065 100644 --- a/two-sum/freemjstudio.py +++ b/two-sum/freemjstudio.py @@ -5,8 +5,8 @@ def twoSum(self, nums: List[int], target: int) -> List[int]: for i in range(len(nums)): current_num = nums[i] diff = target - current_num - if diff in hashmap.keys(): - return [i, hashmap[diff]] + if diff in hashmap.keys(): + return [i, hashmap[diff]] hashmap[current_num] = i # store the index of current num - + return answer diff --git a/valid-anagram/freemjstudio.py b/valid-anagram/freemjstudio.py index 44fa9a12ea..43da0864a5 100644 --- a/valid-anagram/freemjstudio.py +++ b/valid-anagram/freemjstudio.py @@ -1,5 +1,5 @@ """ -첫번째 풀이 +첫번째 풀이 시간 복잡도 : O(n log n) """ @@ -14,19 +14,19 @@ def isAnagram(self, s: str, t: str) -> bool: class Solution: def isAnagram(self, s: str, t: str) -> bool: - # 반례 : s = ab, t = a + # 반례 : s = ab, t = a # 이 경우에는 t에 없는 b가 존재하므로 False를 반환해야 한다. if len(s) != len(t): - return False + return False counter = {} - for ch in s: + for ch in s: counter[ch] = counter.get(ch, 0) + 1 - - for ch in t: + + for ch in t: if ch not in counter: - return False + return False counter[ch] -= 1 if counter[ch] < 0: - return False + return False return True diff --git a/valid-palindrome/freemjstudio.py b/valid-palindrome/freemjstudio.py index f0d2c1c269..3c7d319cca 100644 --- a/valid-palindrome/freemjstudio.py +++ b/valid-palindrome/freemjstudio.py @@ -2,12 +2,12 @@ class Solution: def isPalindrome(self, s: str) -> bool: characters = "abcdefghijklmnopqrstuvwxyz0123456789" s = s.lower() - + filtered = "" - for ch in s: + for ch in s: if ch in characters: - filtered += ch - + filtered += ch + n = len(filtered) left = 0 right = n-1 @@ -15,7 +15,7 @@ def isPalindrome(self, s: str) -> bool: if filtered[left] == filtered[right]: left += 1 right -= 1 - else: + else: return False - + return True \ No newline at end of file From c4b38167d946f6fe75ae25f233c886601249819c Mon Sep 17 00:00:00 2001 From: freemjstudio Date: Sat, 11 Jul 2026 16:54:06 +0900 Subject: [PATCH 17/18] Remove trailing blank line --- top-k-frequent-elements/freemjstudio.py | 1 - 1 file changed, 1 deletion(-) diff --git a/top-k-frequent-elements/freemjstudio.py b/top-k-frequent-elements/freemjstudio.py index ed8cf1c339..ca5228336a 100644 --- a/top-k-frequent-elements/freemjstudio.py +++ b/top-k-frequent-elements/freemjstudio.py @@ -26,4 +26,3 @@ def topKFrequent(self, nums: List[int], k: int) -> List[int]: answer.append(v) return answer - From 1e6b42ac6af29e76b72397d97b2f74ab17c36ba1 Mon Sep 17 00:00:00 2001 From: freemjstudio Date: Sat, 11 Jul 2026 16:57:43 +0900 Subject: [PATCH 18/18] Fix missing final newlines --- combination-sum/freemjstudio.py | 2 +- number-of-1-bits/freemjstudio.py | 2 +- valid-palindrome/freemjstudio.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/combination-sum/freemjstudio.py b/combination-sum/freemjstudio.py index 3dc8bdc42f..d6824f6949 100644 --- a/combination-sum/freemjstudio.py +++ b/combination-sum/freemjstudio.py @@ -20,4 +20,4 @@ def backtracking(start_idx, total, path): path.pop() backtracking(0, 0, []) - return answer \ No newline at end of file + return answer diff --git a/number-of-1-bits/freemjstudio.py b/number-of-1-bits/freemjstudio.py index 9e657f790d..ef95ab1dea 100644 --- a/number-of-1-bits/freemjstudio.py +++ b/number-of-1-bits/freemjstudio.py @@ -12,4 +12,4 @@ def hammingWeight(self, n: int) -> int: count += n % 2 n //=2 - return count \ No newline at end of file + return count diff --git a/valid-palindrome/freemjstudio.py b/valid-palindrome/freemjstudio.py index 3c7d319cca..cb93b4e4e9 100644 --- a/valid-palindrome/freemjstudio.py +++ b/valid-palindrome/freemjstudio.py @@ -18,4 +18,4 @@ def isPalindrome(self, s: str) -> bool: else: return False - return True \ No newline at end of file + return True