标签:rac get put turn contain ash stat key integer
import java.util.HashMap; import java.util.Map; /** * 在字符串中找出第一个只出现一次的字符。如输入"abaccdeff",则输出‘b‘。 * aabb 0 * aba b * aAa A */ public class Third { public static char findFirstNoRepeatChar(String str){ if(str==null||str.trim().length()==0){ return ‘0‘; } int len = str.length(); Map<Character,Integer>map = new HashMap<>(); int count =0; for(int i=0;i<str.length();i++){ if(map.containsKey(str.charAt(i))){ count = map.get(str.charAt(i)); map.put(str.charAt(i),++count); }else { map.put(str.charAt(i),1); } } for (int i=0;i<len;i++){ if(map.get(str.charAt(i))==1){ return str.charAt(i); } } return ‘0‘; } public static void main(String[] args) { System.out.println(findFirstNoRepeatChar("aabb")); System.out.println(findFirstNoRepeatChar("aba")); System.out.println(findFirstNoRepeatChar("aAba")); } }
标签:rac get put turn contain ash stat key integer
原文地址:https://www.cnblogs.com/chengpeng15/p/10759439.html