1/100. Jewels and Stones
class Solution:
def numJewelsInStones(self, J, S):
"""
:type J: str
:type S: str
:rtype: int
"""
res = 0
for s in S:
if s in J:
res += 1
return res
更优解法:
def numJewelsInStones(self, J, S):
return sum(map(J.count, S))
def numJewelsInStones(self, J, S):
return sum(s in J for s in S)