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
10 changes: 10 additions & 0 deletions contains-duplicate/Chanz82.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
  • 설명: 해당 코드는 숫자 등장 여부를 해시맵으로 추적하여 중복 여부를 판단합니다. 매 원소를 확인하며 이미 등장했는지 확인하는 방식으로 중복 탐지를 구현합니다.

📊 시간/공간 복잡도 분석

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

피드백: 해시맵에 방문 여부를 저장해 중복 여부를 인식합니다. 반복마다 상수시간 조회/삽입이 가능하므로 전체 시간은 선형이고 추가 공간도 선형입니다.

개선 제안: 현재 구현은 전통적인 해시맵 기반 풀이로 적절합니다.

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

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Solution:
def containsDuplicate(self, nums: List[int]) -> bool:
hashmap = dict()
sorted(nums)
for num in nums:
if hashmap.get(num, False) == True:
return True
else :
hashmap[num] = True
return False
Comment thread
Chanz82 marked this conversation as resolved.
20 changes: 20 additions & 0 deletions two-sum/Chanz82.py

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Bot님. 질문에 자동응답 하나요?

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,20 @@
class Solution:
def twoSum(self, nums: List[int], target: int) -> List[int]:

## 공간 복잡도 : O(n)
## - n 개수 만큼의 hashmap 공간만을 사용하므로 공간복잡도가 O(n)이라고 생각합니다.

## 시간 복잡도 : O(n)
## - hashmap에 값과 idx를 매칭하는 작업을 n번 수행합니다.
## - 이후 다시 nums를 순회하면서 target이 되는 짝을 찾습니다.
## - 따라서 Worst N번 이므로, 2n = O(n)이라고 생각합니다.

hashmap = dict()

for idx, num in enumerate(nums):
possible_match = target - num
if possible_match in hashmap:
return [idx, hashmap[possible_match]]
else:
hashmap[num] = idx

Loading