1554. Strings Differ by One Character

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

On This Page

LeetCode problem 1554

class Solution:
    def differByOne(self, dict: List[str]) -> bool:
        s = set()
        for word in dict:
            for i in range(len(word)):
                t = word[:i] + "*" + word[i + 1 :]
                if t in s:
                    return True
                s.add(t)
        return False