Answers for "how to check for repeated values in an array"

0

find duplicate in an array using xor

int DuplicateNumber(int arr[], int size){
    /* Don't write main().
     * Don't read input, it is passed as function argument.
     * Return output and don't print it.
     * Taking input and printing output is handled automatically.
     */
    
    int ans=0;
    for(int i=0;i<size;i++){
        ans= ans ^ arr[i] ;
       
    }
    for(int i=0;i<=size-2;i++){
        ans= ans ^ i;
       
    }
    return ans;
    

}
Posted by: Guest on May-18-2020
1

java find duplicates in array

// Uses a set, which does not allow duplicates 

for (String name : names) 
{
     if (set.add(name) == false) 
     {
        // print name your duplicate element
     }
}
Posted by: Guest on May-09-2020

Code answers related to "how to check for repeated values in an array"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language