Leetcode 1697 Solution

This article provides solution to leetcode question 1697 (strings-differ-by-one-character)

https://leetcode.com/problems/strings-differ-by-one-character

Solution

class Solution:
    def differByOne(self, dict: List[str]) -> bool:
        m = len(dict)
        n = len(dict[0])

        for i in range(n):
            res = collections.defaultdict(set)
            for word in dict:
                key = word[0:i] + word[i + 1:]
                res[key].add(word[i])

            for k, v in res.items():
                if len(v) > 1:
                    return True

        return False