java - Finding duplicate elements in an array without using nested loops -


this question has answer here:

i had interview consisted of following problem. please possible solutions.

write method in java find duplicate elements in integer array without using nested loops ( for/ while / while, etc ) , without using library functions or standard api's.

hey below solution has complexity o(n) , works fine. check if helps.

public class main {     public static void main(string[] args) {         int a[] = new int[]{10,3,5,10,5,4,6};         string distinctelement="";         string repetitiveterms="";         for(int i=0;i<a.length;i++){             if(i==0){                 distinctelement+=a[i]+" ";             }             else if(distinctelement.contains(""+a[i])){                 repetitiveterms+=a[i]+" ";             }             else{                 distinctelement+=a[i]+" ";             }         }      } } 

Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -