-
-
Notifications
You must be signed in to change notification settings - Fork 362
[chapse57] Week 2 #2689
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[chapse57] Week 2 #2689
Changes from all commits
c474203
9e53265
6895637
afde7ad
888fb59
9cb02e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이 문제는 5주차 문제인 거 같네요. 주차별 문제는 참고로 여기서 보실 수 있습니다 http://github.com/orgs/DaleStudy/projects/6/
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 정렬 대신 계수 기반 키를 사용하면 더 나은 상수와 함께 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()) | ||
|
|
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 카운트 맵 구축과 정렬으로 전체적으로 합리적이지만, 더 빠른 방식으로는 힙을 사용할 수 있습니다. 개선 제안: 현재 구현이 적절해 보입니다.
|
| 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 | ||
|
|
||
|
|
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 해시맵 사용으로 시간 복잡도를 최적화했습니다. 개선 제안: 현재 구현이 적절해 보입니다.
|
| 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 | ||
|
|
||
|
|
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s와 t를 서로 정렬해서 비교하는 방식을 선택하셨네요! 코드가 직관적이고 깔끔합니다.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 정렬 대신 카운트 배열(알파벳 수)으로 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) | ||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 중복 여부를 선형 시간으로 확인하려면 해시셋 사용이 필요합니다.
개선 제안: 현재 구현은 최악의 경우 시간 복잡도가 O(n^2)에 해당하므로 해시를 이용한 선형 탐색으로 개선 가능