check if N and its double exist in an array (leetcode)

#672
Raw
Author
socdev
Created
Feb. 13, 2023, 7:19 p.m.
Expires
Never
Size
577 bytes
Hits
15
Syntax
Java
Private
No
//Check If N and Its Double Exist

class Solution {
    public boolean checkIfExist(int[] arr) {
        for(int i = 0; i < arr.length; i++){
            int j = 0;
            while(j < arr.length){
                boolean areDifferent = i != j;
                boolean jIsDouble = arr[i] == (2 * arr[j]);
                
                if(areDifferent && jIsDouble) {
                    return true;
                }
                
                j++;
            }
        }
        
        return false;
    }
}