剑指offer 35. 第一次只出现一次的字符
2017-05-05 08:17
274 查看
//题目:输入一个数组,找出第一个只出现一次的字符 //使用辅助空间 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 ' '; } }
相关文章推荐
- 剑指offer:第一次只出现一次的字符
- 剑指offer 35-第一次只出现一次的字符
- 《剑指offer》第一次只出现一次的字符
- 《剑指offer》:[35]第一次出现且只出现一次的字符
- 剑指offer——面试题35:第一次只出现一次的字符
- 剑指offer——第一次只出现一次的字符
- 剑指offer—字符串中第一次只出现一次的字符
- 剑指offer——查找一个字符串中第一次出现一次的字符(哈希直接定址法)
- 剑指offer-第五章优化时间和空间效率(在字符串中第一次出现切只出现一次的字符)
- 剑指Offer(56)第一个只出现一次的字符
- 剑指offer——第一次只出现一次的字符
- JAVA实现 剑指offer—求字符串中第一个只出现一次的字符
- 哈希表初识--查找第一次只出现一次的字符
- 第一个只出现一次的字符 (剑指offer)
- 《剑指offer》——第一个只出现一次的字符位置
- 字符串中第一次出现的只出现一次的字符
- 第一次只出现一次的字符(程序员面试题精选100题)
- 剑指offer系列之33:第一个只出现一次的字符
- 查出第一次只出现一次的字符
- 剑指offer面试题[35]-第一个只出现一次的字符