close
You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. You want to know how many of the stones you have are also jewels.
The letters in J are guaranteed distinct, and all characters in J and S are letters. Letters are case sensitive, so "a" is considered a different type of stone from "A".
解題:看起來是說J中的元素在S中出現的次數,使用雙層迴圈可以簡單地完成
python code:
class Solution: def numJewelsInStones(self, J: str, S: str) -> int: count=0 for i in J: for k in S: if i==k: count+=1 return count
文章標籤
全站熱搜