Code For NonGeek
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Interviewer gave me an array of character and asked me to find first non-repeating character

Go down

Interviewer gave me an array of character and asked me to find first non-repeating character Empty Interviewer gave me an array of character and asked me to find first non-repeating character

Post  skyboard Mon Oct 03, 2011 5:00 pm


public class Firstnonrepeat {
public void first(char[] ch){
int[] count=new int[128];
for(int i=0;i<count.length;i++){
count[i]=0;
}
for(int j=0;j<ch.length;j++){
count[ch[j]]++;
}
for(int k=0;k<ch.length;k++){
if(count[ch[k]]==1){
System.out.println(ch[k]);
return;
}
}
}
public static void main(String[] args){
Firstnonrepeat f=new Firstnonrepeat();
char[] a={'a','a','b','c'};
f.first(a);
}
}

skyboard

Posts : 31
Join date : 2011-09-03

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum