package leetcode;

/**
 * https://leetcode.com/problems/check-if-n-and-its-double-exist/
 */
public class Problem1346 {
    public boolean checkIfExist(int[] arr) {
        // TODO
        return false;
    }

    public static void main(String[] args) {
        Problem1346 prob = new Problem1346();
        System.out.println(prob.checkIfExist(new int[]{10,2,5,3})); // true
        System.out.println(prob.checkIfExist(new int[]{7,1,14,11})); // true
        System.out.println(prob.checkIfExist(new int[]{3,1,7,11})); // false
    }
}

package leetcode;

import java.util.HashSet;
import java.util.Set;

/**
 * https://leetcode.com/problems/check-if-n-and-its-double-exist/
 */
public class Problem1346 {
    public boolean checkIfExist(int[] arr) {
        Set<Integer> set = new HashSet<>();
        int nZero = 0;
        for (int n : arr) {
            if (n == 0) {
                nZero++;
            }
            set.add(n);
        }
        if (nZero > 1) {
            return true;
        }
        for (int n : arr) {
            if (n == 0) {
                continue;
            }
            if (n % 2 == 0 && set.contains(n / 2)) {
                return true;
            }
        }
        return false;
    }
}

Solve problem 1346