-
-
Notifications
You must be signed in to change notification settings - Fork 296
[sonjh1217] WEEK 01 solutions #1985
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
sonjh1217
wants to merge
2
commits into
DaleStudy:main
Choose a base branch
from
sonjh1217: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
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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,14 @@ | ||
| class Solution { | ||
| // time O(n) / space O(n) | ||
| func containsDuplicate(_ nums: [Int]) -> Bool { | ||
| var numSet = Set<Int>() | ||
| for num in nums { | ||
| if numSet.contains(num) { | ||
| return true | ||
| } | ||
| numSet.insert(num) | ||
| } | ||
|
|
||
| return false | ||
| } | ||
| } | ||
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.
swift에서 Set을 사용하였군요
저는 조금 다른 방식으로 풀었는데
Set같은 자료구조가 아닌 주어진 리스트를 정렬 후,
1번 인덱스 부터 현재 인덱스랑 이전 인덱스 비교하며 중복이면 True를 리턴하도록 작성했습니다.
하지만 정렬 자체가 시간 부분에서 O(n*logn)이라 추천하지는 않습니다
코드 리뷰가 처음이라 메일이 계속 왔을텐데.. 다음부터는 제대로 리뷰하겠습니다..