图片说明

class Solution {
  public int numJewelsInStones(String J, String S) {
        HashMap<Character, Integer> hm = new HashMap<Character,Integer>();
        int ans = 0;
        for(int i = 0 ; i < S.length();i++) {
            if(!hm.containsKey(S.charAt(i))){
                hm.put(S.charAt(i), 1);
            }
            else {
                int temp = hm.get(S.charAt(i));
                hm.replace(S.charAt(i), temp+1);
            }            
        }
        for(int i= 0 ; i< J.length();i++) {
            if(hm.containsKey(J.charAt(i)))
                ans+= hm.get(J.charAt(i));
        }
        return ans;
    }
}