LeetCode——宝石与石头

题目描述:J表示的是各种宝石,S表示持有的石头,判断出S中到底有多少个J中的元素,注意是区分大小写的

class Solution {
    public int numJewelsInStones(String J, String S) {
        int res = 0;
        Set set = new HashSet();
        for(char j:J.toCharArray())
            set.add(j);
        for(char s:S.toCharArray())
            if(set.contains(s))
                res++;
        return res;
    }
}

 

相关文章:

  • 2021-06-22
  • 2021-08-12
  • 2021-04-20
  • 2018-03-21
  • 2022-03-05
  • 2021-07-19
  • 2021-09-29
  • 2021-12-27
猜你喜欢
  • 2021-07-08
  • 2021-10-01
  • 2021-10-29
  • 2021-04-26
  • 2021-10-18
  • 2021-06-15
  • 2021-05-04
相关资源
相似解决方案