给定字符串J和S,求S中在J中出现的字符总数。
class Solution(object):
def numJewelsInStones(self, J, S):
"""
:type J: str
:type S: str
:rtype: int
"""
return sum(s in J for s in S)
如果s in S,则返回True , sum(True) = 1 , sum(True,True) = 2