Skip to content
Merged
Changes from 1 commit
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
19 changes: 19 additions & 0 deletions contains-duplicate/taekwon-dev.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Solution {
/**
* 시간 복잡도: O(N)
* - 최악의 경우 주어진 배열의 마지막 원소까지 체크해야 함.
* - 중복 검사를 위해 Set 선택한 이유
* - O(1) 으로 탐색 가능
* - 데이터 순서 보장 필요 없음
*/
public boolean containsDuplicate(int[] nums) {
HashSet<Integer> set = new HashSet<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

알고리즘과 관련없는 이야기인데

변수 선언을

Set<Integer> set = new HashSet<>();

으로 하는게 자바 컨벤션상 더 좋지 않을까 생각이 들었습니다.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dev-jonghoonpark 생각해보니까 interface 로 선언해두는 것이 나중에 다른 구현체로 갈아끼울 때도 더 유연하게 대응할 수 있을 것 같아서 더 좋을 것 같네요 ㅎㅎ 코멘트 감사합니다!

for (int num: nums) {
if (set.contains(num)) {
return true;
}
set.add(num);
}
return false;
}
}