Brute force beating 93.2% in time
Not much algorithm found in this question ..\n\nPerhaps the most subtle point is to convert the nums into a set to avoid duplicated calculation?\n\n# Code\npyth
Not much algorithm found in this question ..\n\nPerhaps the most subtle point is to convert the nums into a set to avoid duplicated calculation?\n\n# Code\n```python3 []\nclass Solution:\n    def countPairs(self, nums: List[int]) -> int:\n        possiblepair = {}\n       \n        res = 0\n        nums = [str(n) for n in nums]\n        m = max([len(s) for s in nums])\n        for i in range(len(nums)):\n            if len(nums[i])!=m:\n                nums[i] = \'0\'*(m-len(nums[i]))+nums[i]\n        @cache\n        def swap(s):\n            m = len(s)\n            res = set([])\n            for i in range(m):\n                for j in range(i+1,m):\n                    res.add(s[:i]+s[j]+s[i+1:j]+s[i]+s[j+1:])\n            return res\n \n        freq = Counter(nums)\n        for s in set(nums):\n            res += freq[s]*(freq[s]-1) \n            change1 = swap(s)\n            changes = set([])\n            for c in change1:\n                change2=swap(c)\n                changes.add(c)\n                for cc in change2:\n                    changes.add(cc)\n            for c in changes:\n                if c in freq and c!=s:\n                    res += freq[c]*freq[s]\n        return res // 2\n            \n        \n```
['Python3']