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

View previous topic View next topic Go down

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

Post  skyboard on 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

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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