-
-
Notifications
You must be signed in to change notification settings - Fork 363
[chapse57] Week 3 #2722
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
Open
chapse57
wants to merge
7
commits into
DaleStudy:main
Choose a base branch
from
chapse57:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[chapse57] Week 3 #2722
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c474203
Add contains-duplicate solution
chapse57 9e53265
[chapse57] Week 1
chapse57 6895637
fix: add final newline
chapse57 afde7ad
[chapse57] Week 2
chapse57 888fb59
[chapse57] Week 2 - Group Anagrams
chapse57 9cb02e4
fix: add final newline
chapse57 b21959a
[chapse57] Week 3
chapse57 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| class Solution(object): | ||
| def climbStairs(self, n): | ||
| """ | ||
| :type n: int | ||
| :rtype: int | ||
| """ | ||
|
|
||
|
|
||
| if n == 1: | ||
| return 1 | ||
| if n == 2: | ||
| return 2 | ||
| a = 1 | ||
| b = 2 | ||
|
|
||
| for i in range(n - 2): | ||
| c = a + b | ||
| a = b | ||
| b = c | ||
| return c | ||
|
|
|
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) 시간으로 개선 가능하지만 현재 구조를 유지하는 경우도 있습니다.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()) | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
|
|
||
|
|
||
|
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🏷️ 알고리즘 패턴 분석
📊 시간/공간 복잡도 분석
피드백: 두 인접한 항의 합으로 다음 수를 계산하므로 시간은 선형이고 추가 공간은 상수입니다.
개선 제안: 현재 구현이 적절해 보입니다.