package java_study.JianZhiOffer;
import org.junit.Test;
import java.util.HashMap;
/**
* Created by ethan on 2015/6/29.
* 剑指offer 直接使用hashmap或者使用更加轻量级的数组都行
*/
public class No35找到第一个只出现一次的数 {
public char findFirstOnlyCount1(String str){
HashMap<Character, Integer> map = new HashMap<Character, Integer>();
for (int i=0; i<str.length(); i++){
if(!map.keySet().contains(str.charAt(i))){
map.put(str.charAt(i), 1);
}else
map.put(str.charAt(i), map.get(str.charAt(i))+1);
}
// find the first number which appear once
for (int i=0 ;i<str.length(); i++){
if (map.get(str.charAt(i))==1){
return str.charAt(i);
}
}
return 0;
}
@Test
public void test(){
System.out.println(findFirstOnlyCount1("jjaskdfankdnfioaeniufae")) ;
}
}