
-Code
import java.util.*;
class Solution {
public boolean containsDuplicate(int[] nums) {
Set<Integer> numsSet = new HashSet<>();
for (int i = 0; i < nums.length; i++) {
// 찾는 속도가 O(1)이므로 Set을 이용해 검사
if (numsSet.contains(nums[i])) {
return true;
}
numsSet.add(nums[i]);
}
return false;
}
}'Beakjoon&프로그래머스 > Java' 카테고리의 다른 글
| [LeetCode/Java] Two Sum (0) | 2025.12.31 |
|---|---|
| [LeetCode/Java] Valid Anagram (0) | 2025.12.31 |
| [백준/Java] 32400번 다트판 (0) | 2025.12.31 |
| [백준/Java] 24479번 알고리즘 수업 - 깊이 우선 탐색 1 (0) | 2025.12.30 |
| [백준/Java] 2580번 스도쿠 (0) | 2025.12.30 |