【LeetCode每日一题】[简单]771. 宝石与石头

【LeetCode每日一题】[简单]771. 宝石与石头

771. 宝石与石头

题目来源
算法思想:搜索二叉树

题目:在这里插入图片描述

java代码

class Solution {
    
    
	    public int numJewelsInStones(String J, String S) {
    
    
	        boolean[] m = new boolean[128];//标记数组
	        char[] a = J.toCharArray();
	        char[] b = S.toCharArray();
	        int res = 0;
	        for (int i = 0; i < a.length; i++) {
    
    
				m[a[i]] = true;//统计宝石
			}
	        for (int i = 0; i < b.length; i++) {
    
    
				if (m[b[i]] == true) {
    
    //判断是否有宝石
					res++;
				}
			}
	        return res;
	    }
	}

猜你喜欢

转载自blog.csdn.net/qq_39457586/article/details/108905107