LeetCode高频面试60天打卡日记Day17

day17(拼写单词)

在这里插入图片描述

class Solution {
    
    
    public int countCharacters(String[] words, String chars) {
    
    
        int[] hash = new int[26];
        for(char c:chars.toCharArray()){
    
    
            hash[c-'a'] += 1;
        }
        
        int[] map = new int[26];
        int len = 0;
        for(int i=0;i<words.length;i++){
    
    
            String word = words[i];
            Arrays.fill(map,0);
            boolean flag = true;
            for(char c:words[i].toCharArray()){
    
    
                map[c-'a'] ++;
                if(map[c-'a']>hash[c-'a']){
    
    
                    flag = false;
                }
            }
            if(flag){
    
    
                len+=word.length();
            }else{
    
    
                len+=0;
            }
        }
        return len;
    }
}

猜你喜欢

转载自blog.csdn.net/YoungNUAA/article/details/104955372