Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions contains-duplicate/chapse57.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Brute Force, Hash Map / Hash Set
  • 설명: 코드는 이중 루프를 이용해 모든 쌍을 비교하므로 직접적인 브루트 포스 접근이며, 해시맵/해시셋은 사용하지 않지만 중복 여부를 확인하는 문제의 전형적인 예시로 패턴은 중복 탐지의 일반적 아이디어와 매칭됩니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n^2)
Space O(1)

피드백: 중첩 루프를 통해 모든 쌍을 검사하므로 최악의 경우 모든 쌍을 비교합니다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution(object):
def containsDuplicate(self, nums):
"""
:type nums: List[int]
:rtype: bool
"""
for i in range(len(nums)):
for j in range(i+1,len(nums)):
if nums[i] == nums[j]:
return True
return False
22 changes: 22 additions & 0 deletions top-k-frequent-elements/chapse57.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Greedy
  • 설명: 숫자별 등장 횟수를 해시 맵으로 집계하고, 등장 횟수를 기준으로 내림차순 정렬하여 상위 k개를 선택합니다. 직접적 최적화보다는 빈도 기반의 선택으로 문제를 해결합니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n log n)
Space O(n)

피드백: 빈도수를 세고 정렬하는 일반적 방법이며, 최악의 경우 모든 고유값에 대해 정렬합니다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class Solution(object):
def topKFrequent(self, nums, k):
"""
:type nums: List[int]
:type k: int
:rtype: List[int]
"""
count = {}
for n in nums:
if n in count:
count[n] +=1
else:
count[n] =1
# count.items()를 횟수 큰 순으로 정렬
freq = sorted(count.items(), key=lambda x: x[1], reverse=True)

result = []
for x in freq[:k]:
result.append(x[0])
return result


14 changes: 14 additions & 0 deletions two-sum/chapse57.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Hash Map / Hash Set, Two Pointers
  • 설명: 해당 코드는 한 번의 순회로 해결하는 해시 맵 기반 풀이로, 이미 본 값들을 저장하고 필요한 보수를 확인한다. 따라서 해시 맵 패턴이 주로 사용되며, 입력 순서를 이용해 보수를 찾는 방식은 간접적으로 투 포인터와도 연결될 수 있다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n)
Space O(n)

피드백: 해시맵으로 조회/저장을 통해 선형 시간에 풀이합니다.

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Solution(object):
def twoSum(self, nums, target):
"""
:type nums: List[int]
:type target: int
:rtype: List[int]
"""
seen = {}
for i in range(len(nums)):
if (target - nums[i]) in seen:
return [seen[target - nums[i]],i]
seen[nums[i]] =i


11 changes: 11 additions & 0 deletions valid-anagram/chapse57.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🏷️ 알고리즘 패턴 분석

  • 패턴: Sorting
  • 설명: 두 문자열을 정렬한 뒤 비교하는 방식으로 같은 문자로 구성되었는지 판단하므로 정렬 기반 패턴으로 분류할 수 있습니다. 이 문제는 전체 문자열을 정렬하는 것이 핵심 아이디어입니다.

📊 시간/공간 복잡도 분석

복잡도
Time O(n log n)
Space O(n)

피드백: 정렬 비용이 주된 시간 복잡도이며, 추가 공간은 정렬에 사용하는 임시 공간

개선 제안: 현재 구현이 적절해 보입니다.

💡 풀이에 시간/공간 복잡도를 주석으로 남겨보세요!

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class Solution(object):
def isAnagram(self, s, t):
"""
:type s: str
:type t: str
:rtype: bool
"""
return sorted(s) == sorted(t)



Loading