-
-
Notifications
You must be signed in to change notification settings - Fork 246
[s0ooo0k] WEEK 01 solutions #1709
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
Conversation
Set<Integer> set = new HashSet<>(); | ||
|
||
for(int n : nums) { | ||
if(set.contains(n)){ |
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.
Set을 이용한 제너럴한 문제 풀이를 하시긴 했는데
이렇게 되면 중복이 나올때까지, contains와 add 두개의 함수가 매번 호출되니까,
add를 할 때, 실패하면 한번의 함수로 판단할 수 있습니다.
public boolean containsDuplicate(int[] nums) {
Set<Integer> set = new HashSet<>();
for (int num : nums) {
boolean isAdded = set.add(num);
if (!isAdded) {
return true;
}
}
return false;
}
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.
더 좋은 방법이네요! 감사합니다!
두번 째 문제는 오늘, 내일 중으로 리뷰하겠습니다!! (two sum) |
* 시간복잡도 O(n) | ||
* 공간복잡도 O(n) | ||
*/ | ||
public int[] twoSum(int[] nums, int target) { |
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.
lgtm
두개만 푸시는건가요? 일단 approve 해드렸습니다 :) |
네, Week1 풀이를 늦게 시작하여 두문제만 진행하였습니다 :) |
답안 제출 문제
작성자 체크 리스트
In Review
로 설정해주세요.검토자 체크 리스트
Important
본인 답안 제출 뿐만 아니라 다른 분 PR 하나 이상을 반드시 검토를 해주셔야 합니다!