LeetCode #771: Jewels and Stones
• 59 words • 1 min
LeetCode #771: Jewels and Stones:
Cozy:
python
class Solution:
def numJewelsInStones(self, jewels: str, stones: str) -> int:
s = set(jewels)
ans = 0
for stone in stones:
if stone in s:
ans += 1
return ansOne-liner:
python
class Solution:
def numJewelsInStones(self, jewels: str, stones: str) -> int:
s = set(jewels)
return sum(stone in s for stone in stones)∎
Connections
Shared tags