2351. First Letter to Appear Twice

Updated: 2024-03-12
1 min read
[]

On This Page

LeetCode problem 2351

class Solution:
    def repeatedCharacter(self, s: str) -> str:
        mask = 0
        for c in s:
            i = ord(c) - ord('a')
            if mask >> i & 1:
                return c
            mask |= 1 << i