thiagowfx's avatar

¬ just serendipity 🍀 (not just serendipity)

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 ans

One-liner:

python
class Solution:
    def numJewelsInStones(self, jewels: str, stones: str) -> int:
        s = set(jewels)
        return sum(stone in s for stone in stones)