
解题思路
- 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
解题思路
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
本文标题:LeetCode-771-宝石与石头
本文链接:https://www.haomeiwen.com/subject/eszdpktx.html
网友评论