在字符串 s 中找出第一个只出现一次的字符。如果没有,返回一个单空格。 s 只包含小写字母。
示例:
s = "abaccdeff"
返回 ‘b‘
示例:
s = ""
返回 ‘ ‘
1 class Solution { 2 public char firstUniqChar(String s) { 3 char[] array = s.toCharArray(); 4 Map<Character,Boolean> map = new HashMap<>(); 5 for(char c : array){ 6 map.put(c,!map.containsKey(c)); 7 } 8 for(char ch : array){ 9 if(map.get(ch)){ 10 return ch; 11 } 12 } 13 return ‘ ‘; 14 } 15 }
原文:https://www.cnblogs.com/0error0warning/p/13617473.html