@@ -0,0 +1,988 @@
+# Time:  O(n)%0A# Space: O(1)%0A%0A# Given two strings A and B of lowercase letters,%0A# return true if and only if we can swap two letters in A%0A# so that the result equals B.%0A#%0A# Example 1:%0A#%0A# Input: A = %22ab%22, B = %22ba%22%0A# Output: true%0A# Example 2:%0A#%0A# Input: A = %22ab%22, B = %22ab%22%0A# Output: false%0A# Example 3:%0A#%0A# Input: A = %22aa%22, B = %22aa%22%0A# Output: true%0A# Example 4:%0A#%0A# Input: A = %22aaaaaaabc%22, B = %22aaaaaaacb%22%0A# Output: true%0A# Example 5:%0A#%0A# Input: A = %22%22, B = %22aa%22%0A# Output: false%0A#%0A# Note:%0A# - 0 %3C= A.length %3C= 20000%0A# - 0 %3C= B.length %3C= 20000%0A# - A and B consist only of lowercase letters.%0A%0Aimport itertools%0A%0A%0Aclass Solution(object):%0A    def buddyStrings(self, A, B):%0A        %22%22%22%0A        :type A: str%0A        :type B: str%0A        :rtype: bool%0A        %22%22%22%0A        if len(A) != len(B):%0A            return False%0A        diff = %5B(a, b) for a, b in itertools.izip(A, B) if a != b%5D%0A        return (not diff and len(set(A)) %3C len(A)) or %5C%0A               (len(diff) == 2 and diff%5B0%5D == diff%5B1%5D%5B::-1%5D)%0A

Create buddy-strings.py