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)