Find Words That Can Be Formed by Characters

给一个字符串组和一个字符串s, 问s里面的字符能组成几个字符串组里的字符串. 返回这些字符串的长度和.

class Solution {
    public int countCharacters(String[] words, String chars) {
        int res = 0;
        int[] c = count(chars);
        for(String s : words) {
            int[] t = count(s);
            for(int i = 0; i <= 26; i++) {
                if(i == 26){
                    res += s.length();
                    break;
                }
                if(t[i] > c[i])
                    break;
            }
        }
        return res;
    }
    
    private int[] count(String s) {
        int[] count = new int[26];
        for(char c : s.toCharArray())
            count[c - 'a'] ++;
        return count;
    }
}