## 771宝石与石头(哈希表)

771宝石与石头(哈希表)

在这里插入图片描述

class Solution {
    
    
    public int numJewelsInStones(String jewels, String stones) {
    
    
        HashSet<Character> ss = new HashSet<Character>();
        for(int i=0; i<jewels.length(); i++){
    
    
            ss.add(jewels.charAt(i));
        }
        int ans = 0;
        for(int i=0; i<stones.length(); i++){
    
    
            if(ss.contains(stones.charAt(i))){
    
    
                ans++;
            }
        }
        return ans;
    }
}

猜你喜欢

转载自blog.csdn.net/qq_40310710/article/details/113008589