최대 1 분 소요

Python

class Solution:
    def buddyStrings(self, s: str, goal: str) -> bool:
        count = 0
        if len(s) != len(goal) or sorted(s) != sorted(goal):
            return False
        
        if s == goal:
            if len(set(s)) < len(s):
                return True
            else:
                return False
        
        for i in range(len(s)):
            if s[i] != goal[i]:
                count += 1
            if count > 2:
                return False
        
        return True

댓글남기기