给你一个字符串 jewels 代表石头中宝石的类型,另有一个字符串 stones 代表你拥有的石头。 stones 中每个字符代表了一种你拥有的石头的类型,你想知道你拥有的石头中有多少是宝石。
字母区分大小写,因此 "a" 和 "A" 是不同类型的石头。
class Solution {
public int numJewelsInStones(String jewels, String stones) {
char[] chars1=jewels.toCharArray();
char[] chars2=stones.toCharArray();
int count=0;
for (char a : chars1) {
for (char b : chars2) {
if(a==b){
count++;
}
}
}
return count;
}
}