统计字符串出现次数(Java)

public class CountTheNumberOfPerCharacter {
    public static void countTheNumberOfPerCharacter(String s){

        char[] array=s.toCharArray();
        int[] hash=new int[128];
        for(int i=0;i0){
                System.out.print((char)i+":"+hash[i]+"    ");
            }
        }


    }

    public static void main(String[] args) {
        String s="aaabbbccde";
        countTheNumberOfPerCharacter(s);
    }
}

输出:

a:3    b:3    c:2    d:1    e:1    

你可能感兴趣的:(LeetCode题目)