Interviewer gave me an array of character and asked me to find first non-repeating character
Page 1 of 1
Interviewer gave me an array of character and asked me to find first non-repeating character
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
Similar topics
» Find a point in an array where sum of left side array members(wrt to that point) and right side(wrt to that point) are equal..in other words equilibrium point.
» Find pairs in an array that sum to y
» Find the n-th largest int in an array
» An array of integers, all appear twice except one, find this number.
» Find the number of inversions in an array
» Find pairs in an array that sum to y
» Find the n-th largest int in an array
» An array of integers, all appear twice except one, find this number.
» Find the number of inversions in an array
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|