算法题:返回字符串中出现次数最多的字符,如果次数相同,则放回ASCII码最小的那个字符

	public static Character mostFrequentLetter(String string) {
        // TODO: 实现这个方法
    	Character character = null;
        char[] c = string.toCharArray();
        if(c.length>0){
            Map map = new HashMap();
            for(int i = 0;i iterator = map.keySet().iterator();
            while(iterator.hasNext()){
                Character ch = iterator.next();
                int chCount = map.get(ch);
                if(chCount>tempCount){
                    tempCount = chCount;
                    character = ch;
                }else if (chCount == tempCount) {
                	if(ch < character) {
                		tempCount = chCount;
                        character = ch;
                	}
                }
            }
        }
        return character;
    }

你可能感兴趣的:(算法题:返回字符串中出现次数最多的字符,如果次数相同,则放回ASCII码最小的那个字符)