Java accepted, Python TLE
Code\njava []\nclass Solution {\n    public int countPairs(int[] nums) {\n        int ans = 0;\n\n        for (int i = 0; i < nums.length; i++) {\n            f
# Code\n```java []\nclass Solution {\n    public int countPairs(int[] nums) {\n        int ans = 0;\n\n        for (int i = 0; i < nums.length; i++) {\n            for (int j = i + 1; j < nums.length; j++) {\n                String a = String.valueOf(nums[i]);\n                String b = String.valueOf(nums[j]);\n\n                while (a.length() < b.length()) a = "0" + a;\n                while (b.length() < a.length()) b = "0" + b;\n\n                int curr = 0;\n                int p = -1, q = -1, r = -1, s = -1;\n\n                for (int k = 0; k < a.length(); k++) {\n                    if (a.charAt(k) != b.charAt(k)) {\n                        curr++;\n                        if (p == -1) {\n                            p = k;\n                        } else if (q == -1) {\n                            q = k;\n                        } else if (r == -1) {\n                            r = k;\n                        } else if (s == -1) {\n                            s = k;\n                        } else {\n                            break;\n                        }\n                    }\n                }\n\n                if ((curr == 0) || \n                    (curr == 2 && a.charAt(p) == b.charAt(q) && a.charAt(q) == b.charAt(p)) || \n                    (curr == 4 && (\n                        (a.charAt(p) == b.charAt(q) && a.charAt(q) == b.charAt(p) && a.charAt(r) == b.charAt(s) && a.charAt(s) == b.charAt(r)) ||\n                        (a.charAt(p) == b.charAt(r) && a.charAt(r) == b.charAt(p) && a.charAt(q) == b.charAt(s) && a.charAt(s) == b.charAt(q)) ||\n                        (a.charAt(p) == b.charAt(s) && a.charAt(s) == b.charAt(p) && a.charAt(r) == b.charAt(q) && a.charAt(q) == b.charAt(r))\n                    )) ||\n                    (curr == 3 && (\n                        (a.charAt(p) == b.charAt(q) && a.charAt(q) == b.charAt(r) && a.charAt(r) == b.charAt(p)) ||\n                        (a.charAt(p) == b.charAt(r) && a.charAt(q) == b.charAt(p) && a.charAt(r) == b.charAt(q))\n                    ))) {\n                    ans++;\n                }\n            }\n        }\n\n        return ans;\n    }\n}\n```\n```python []\nclass Solution:\n    def countPairs(self, nums: List[int]) -> int:\n        ans = 0\n        for i in range(len(nums)):\n            for j in range(i+1,len(nums)):\n                a = str(nums[i])\n                b = str(nums[j])\n                if len(a)<len(b):\n                    a = \'0\'*(len(b)-len(a)) + a\n                else:\n                    b = \'0\'*(len(a)-len(b)) + b\n                curr = 0\n                p = -1\n                q = -1\n                r = -1\n                s = -1\n                for k in range(len(a)):\n                    if a[k]!=b[k]:\n                        curr += 1\n                        if p==-1:\n                            p = k\n                        elif q==-1:\n                            q = k\n                        elif r==-1:\n                            r = k\n                        elif s==-1:\n                            s = k\n                        else:\n                            break\n                if (curr == 2 and a[p] == b[q] and a[q] == b[p]) or (curr==0):\n                    ans += 1\n                if curr == 4:\n                    if a[p]==b[q] and a[q]==b[p] and a[r]==b[s] and a[s]==b[r]:\n                        ans += 1\n                    elif a[p]==b[r] and a[r]==b[p] and a[q]==b[s] and a[s]==b[q]:\n                        ans += 1\n                    elif a[p]==b[s] and a[s]==b[p] and a[r]==b[q] and a[q]==b[r]:\n                        ans += 1\n                if curr == 3:\n                    if a[p]==b[q] and a[q]==b[r] and a[r]==b[p]:\n                        ans += 1\n                    elif a[p]==b[r] and a[q]==b[p] and a[r]==b[q]:\n                        ans += 1\n        return ans\n\n```
['Java', 'Python3']