Skip to content
Merged
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
  • 설명: 중첩 루프를 이용해 모든 쌍을 비교하는 가장 기초적인 탐색 방식으로 중복 여부를 확인합니다. 보통 효율성은 낮아 대규모 입력에 비효율적입니다.

📊 시간/공간 복잡도 분석

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

피드백: 중복 여부를 선형 시간으로 확인하려면 해시셋 사용이 필요합니다.

개선 제안: 현재 구현은 최악의 경우 시간 복잡도가 O(n^2)에 해당하므로 해시를 이용한 선형 탐색으로 개선 가능

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

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
17 changes: 17 additions & 0 deletions group-anagrams/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.

이 문제는 5주차 문제인 거 같네요. 주차별 문제는 참고로 여기서 보실 수 있습니다 http://github.com/orgs/DaleStudy/projects/6/

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
  • 설명: 문자열을 정렬한 키를 해시 맵에 매핑해 그룹화하는 방식으로 중복을 제거하고 묶는 패턴이다. 키 생성과 맵 업데이트로 그룹을 구성하는 전형적 해시 기반 패턴입니다.

📊 시간/공간 복잡도 분석

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

피드백: 정렬 대신 계수 기반 키를 사용하면 더 나은 상수와 함께 O(n * k) 성능 가능

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

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class Solution(object):
def groupAnagrams(self, strs):
"""
:type strs: List[str]
:rtype: List[List[str]]
"""
seen = {}
for word in strs:
key = "".join(sorted(word))
# key가 seen에 이미 있으면 → word 추가
# 없으면 → 새로 만들기
if key in seen:
seen[key].append(word)
else:
seen[key] = [word]
return list(seen.values())

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, Sorting
  • 설명: 해당 코드는 먼저 해시 맵으로 각 원소의 등장 횟수를 집계하고, 등장 횟수를 기준으로 내림차 sorting하여 상위 k개를 선택한다. 따라서 Hash Map과(를 이용한) 정렬 패턴이 주로 보인다.

📊 시간/공간 복잡도 분석

복잡도
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 Sum의 대표적 패턴이다.

📊 시간/공간 복잡도 분석

복잡도
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.

s와 t를 서로 정렬해서 비교하는 방식을 선택하셨네요! 코드가 직관적이고 깔끔합니다.
다만 이 방식은 sort를 사용하기 때문에 O(n log n)만큼의 시간복잡도가 발생합니다.
저는 주언어가 js기 때문에 Map을 사용해서 해결했고, python에서는 이와 유사한 dictionary를 사용해 O(n)으로 최적화해볼 수 있을 것 같습니다.

  • 해결 방식 : { 문자(key) : 개수(value) }의 형태의 Dictionary를 사용합니다. s와 t를 순회하면서 각 문자의 등장 횟수를 count에 넣어 갯수만으로 두 Dictionary가 일치한지 판별하는 방법입니다.

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.

🏷️ 알고리즘 패턴 분석

  • 패턴: Binary Search, Hash Map / Hash Set, Greedy, Divide and Conquer, Two Pointers, Sliding Window, Fast & Slow Pointers, BFS, DFS, Backtracking, Dynamic Programming, Monotonic Stack, Heap / Priority Queue, Union Find, Trie, Bit Manipulation
  • 설명: 주어진 코드는 두 문자열의 아나그램 여부를 간단히 비교하는 것으로, 문자 정렬 후 동일 여부를 비교합니다. 정렬 자체가 기본적으로 비교를 위한 정렬 기반의 접근이며, 원소의 존재 여부를 확인하는 간접적 패턴으로 볼 수 있습니다.

📊 시간/공간 복잡도 분석

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

피드백: 정렬 대신 카운트 배열(알파벳 수)으로 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