Check If N and its Double Exist LeetCode

 class Solution {

    public boolean checkIfExist(int[] arr) {

        int n=arr.length;

        int count1=0;

int count2=0;

ArrayList<Integer>set=new ArrayList<Integer>();

for(int i=0;i<n;i++){

set.add(arr[i]);

}

for(int i=0;i<n;i++){

if(set.contains(2*arr[i])){

if(arr[i]==0){

count1++;

}

else{

count2++;

break;

}

}

}

if(count2!=0 && count1==0){

//System.out.println("true");

            return true;

}

else if(count2!=0 && count1!=0){

//System.out.println("true");

            return true;

}

else if(count2==0 && count1!=0){

if(Collections.frequency(set,0)>1){

//System.out.println("true");

                return true;

            }

            

else{

//System.out.println("false");

                return false;

            }

}

else{

//System.out.println("false");

            return false;

}

    }

}

Comments

Popular posts from this blog

Solutions Of Practice Questions Dated 01-06-2022

CODEFORCES SPY DETECTED ROUND 713

Maximum Winning Score Geeks For Geeks