LeetCode-771-宝石与石头
2020-10-13 本文已影响0人
阿凯被注册了
image.png
解题思路
- J不重复,则令J为字典;
- 遍历S,若S[i]在J中则结果+1。
Python3代码
class Solution:
def numJewelsInStones(self, J: str, S: str) -> int:
j = set(J)
ans=0
for i in S:
if i in j:
ans+=1
return ans