Skip to content

[kimbro97] WEEK 01 solutions #1139

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

Closed
wants to merge 1 commit into from
Closed
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
15 changes: 15 additions & 0 deletions contains-duplicate/kimbro97.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import java.util.HashSet;

class Solution {
public boolean containsDuplicate(int[] nums) {
HashSet<Integer> numSet = new HashSet<>();
for (int i = 0; i < nums.length; i++) {

if (numSet.contains(nums[i])) {
return true;
}
numSet.add(nums[i]);
Copy link
Contributor

Choose a reason for hiding this comment

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

HashSet 을 이용하여 중복된 숫자를 찾는 방식이네요. 저도 동일한 방식으로 풀었는데, kimbro97 님의 코드를 보니, return 이후에 굳이 else 를 쓰지 않으니 코드가 더 깔끔하네요. 👍

}
return false;
}
}