771. Jewels and Stones
https://leetcode.com/problems/jewels-and-stones/
js
/**
* @param {string} J
* @param {string} S
* @return {number}
*/
var numJewelsInStones = function(J, S) {
let count = 0
for (let s of S.split('')) {
if (J.indexOf(s) >= 0) {
count++
}
}
return count
}
py
class Solution:
def numJewelsInStones(self, J, S):
"""
:type J: str
:type S: str
:rtype: int
"""
count = 0
for s in S:
if s in J:
count += 1
return count