class Solution {
public int numJewelsInStones(String jewels, String stones) {
int ans = 0;
int jewelsLength = jewels.length();
int stonesLength = stones.length();
Set<Character> set = new HashSet<>();
for(int i = 0; i < jewelsLength; i++) {
set.add(jewels.charAt(i));
}
for(int i = 0; i < stonesLength; i++) {
if(set.contains(stones.charAt(i))) {
ans++;
}
}
return ans;
}
}
算法-哈希表-宝石与石头
猜你喜欢
转载自blog.csdn.net/qq_45100361/article/details/113061547
今日推荐
周排行