class Solution {
public int numJewelsInStones(String jewels, String stones) {
Set<Character> set1 = new HashSet<Character>();
for(int i=0;i<jewels.length();i++){
set1.add(jewels.charAt(i));
}
int result = 0;
for(int j=0; j<stones.length(); j++){
if(set1.contains(stones.charAt(j))){
result++;
}
}
return result;
}
}
与349寻找两个数组的交集,思路一致。