Skip to content
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;
}
}