//题目:输入一个数组,找出第一个只出现一次的字符
//使用辅助空间
public class Main {
public static void main(String[] args) throws Exception {
System.out.println(findFirstChar("abaccdeff"));
}
public static char findFirstChar(String str){
if(str == null){
return ' ';
}
HashMap<Character, Integer> m = new HashMap<Character, Integer>();
for(int i = 0;i<str.length();i++){
char temp = str.charAt(i);
int count = 1;
if(m.containsKey(temp)){
count = m.get(temp)+1;
}
m.put(temp, count);
}
for(int i = 0;i<str.length();i++){
char temp = str.charAt(i);
if(m.get(temp) == 1){
return temp;
}
}
System.out.println("not found");
return ' ';
}
}