[LeetCode] 771. Jewels and Stones (javascript)
728x90
반응형
/**
* @param {string} J
* @param {string} S
* @return {number}
*/
var numJewelsInStones = function(J, S) {
const cnt={};
for(let i=0;i<S.length;i+=1){
if(!cnt[S[i]]){
cnt[S[i]]=1;
}else{
cnt[S[i]]+=1;
}
}
let sum=0;
for(let i=0;i<J.length;i+=1){
if(cnt[J[i]]){
sum+=cnt[J[i]];
}
}
return sum;
};
728x90
반응형
'Leetcode' 카테고리의 다른 글
[LeetCode] 347. Top K Frequent elements (javascript) (0) | 2020.12.19 |
---|---|
[LeetCode]3. Longest Substring without repeating characters (javascript) (0) | 2020.12.19 |
[LeetCode] 739. Daily Temperatures (javascript) (0) | 2020.12.18 |
[LeetCode] 316. Remove Duplicate letters (javascript) (0) | 2020.12.18 |
[LeetCode] 121. Best time to buy and sell stock (javascript) (0) | 2020.12.18 |
TAGS.