771. 宝石与石头

图片说明

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;
    }
}
全部评论

相关推荐

也许是天气_:放在双9简历池里也是中上简历,没人指导一是看不懂,二是可能在偷偷抄你简历亮点。如果大厂0面,多半是卡学历了。我觉得你这情况不愁offer,找工作跟投资一样的,90%的时间都是在等待。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务