JAVA_LeetCode 1346_Check If N and Its Double Exist


JAVA_LeetCode 1346_Check If N and Its Double Exist

JAVA_LeetCode 1346_Check If N and Its Double Exist 풀이 class Solution { public boolean checkIfExist(int[] arr) { Set<Integer> set = new HashSet<>(); // 2 * i 또는 i / 2의 몫이 있으며 i가 짝수인경우 true를 반환한다. for (int i : arr) { if (set.contains(i * 2) || (i % 2 == 0 && set.contains(i / 2))) return true; set.add(i); } return false; } } i = 0에서 배열까지 반복해서 arr-1의 길이를 가진 set을 만든다. set에 요소값을 넣기 전, 현 요소값을 조건에 맞춰 비교한다. * 출처 https://leetcode.com/problems/check-if-n-and-its-double-exist...


#JAVA #JAVA_CheckIfNandItsDoubleExist #JAVA_LeetCode1346 #JAVA_LeetCode1346_CheckIfNandItsDoubleExist #LeetCode1346_CheckIfNandItsDoubleExist

원문링크 : JAVA_LeetCode 1346_Check If N and Its Double Exist