Skip to content

Latest commit

 

History

History
22 lines (20 loc) · 581 Bytes

1790.md

File metadata and controls

22 lines (20 loc) · 581 Bytes

1790. Check if One String Swap Can Make Strings Equal

Solution 1 (time O(n), space O(1))

class Solution(object):
    def areAlmostEqual(self, s1, s2):
        """
        :type s1: str
        :type s2: str
        :rtype: bool
        """
        inds = []
        for i in range(len(s1)):
            if s1[i] != s2[i]:
                inds.append(i)
        if len(inds) == 0:
            return True
        if len(inds) == 2 and s1[inds[0]] == s2[inds[1]] and s1[inds[1]] == s2[inds[0]]:
            return True
        return False