Simple and easy solution (100% memory and time beats)
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:O(N^2)\n\n# Code\n```java []\nclass Solution {\n    public boolean ist(int a, int b) {\n        String s = Integer.toString(a);\n        String s1 = Integer.toString(b);\n        \n        // Ensure s is the shorter or same length string\n        if (s.length() > s1.length()) {\n            String temp = s;\n            s = s1;\n            s1 = temp;\n        }\n        \n        // Pad the shorter string with leading zeros\n        StringBuilder sb = new StringBuilder(s);\n        while (sb.length() < s1.length()) {\n            sb.insert(0, \'0\');\n        }\n        s = sb.toString();\n\n        int cnt = 0;\n        int[] f1 = new int[10];\n        int[] f2 = new int[10];\n        List<Integer> diffIndices = new ArrayList<>();\n\n        for (int i = 0; i < s.length(); i++) {\n            f1[s.charAt(i) - \'0\']++;\n            f2[s1.charAt(i) - \'0\']++;\n            if (s.charAt(i) != s1.charAt(i)) { \n                cnt++;\n                diffIndices.add(i);\n            }\n        }\n\n        if (!Arrays.equals(f1, f2)) return false;\n        if (cnt == 0 || cnt == 2 || cnt == 3) return true;\n\n        if (cnt == 4) {\n            int a1 = diffIndices.get(0);\n            int b1 = diffIndices.get(1);\n            int c1 = diffIndices.get(2);\n            int d1 = diffIndices.get(3);\n\n            return (s.charAt(a1) == s1.charAt(b1) && s.charAt(b1) == s1.charAt(a1) && s.charAt(c1) == s1.charAt(d1) && s.charAt(d1) == s1.charAt(c1)) ||\n                   (s.charAt(a1) == s1.charAt(c1) && s.charAt(c1) == s1.charAt(a1) && s.charAt(b1) == s1.charAt(d1) && s.charAt(d1) == s1.charAt(b1)) ||\n                   (s.charAt(a1) == s1.charAt(d1) && s.charAt(d1) == s1.charAt(a1) && s.charAt(b1) == s1.charAt(c1) && s.charAt(c1) == s1.charAt(b1)) ||\n                   (s1.charAt(a1) == s.charAt(b1) && s1.charAt(b1) == s.charAt(a1) && s1.charAt(c1) == s.charAt(d1) && s1.charAt(d1) == s.charAt(c1)) ||\n                   (s1.charAt(a1) == s.charAt(c1) && s1.charAt(c1) == s.charAt(a1) && s1.charAt(b1) == s.charAt(d1) && s1.charAt(d1) == s.charAt(b1)) ||\n                   (s1.charAt(a1) == s.charAt(d1) && s1.charAt(d1) == s.charAt(a1) && s1.charAt(b1) == s.charAt(c1) && s1.charAt(c1) == s.charAt(b1));\n        }\n\n        return false;\n    }\n\n    public int countPairs(int[] nums) {\n        int ans = 0;\n        Map<Integer, Integer> m = new HashMap<>();\n\n        for (int num : nums) {\n            m.put(num, m.getOrDefault(num, 0) + 1);\n        }\n\n        List<Integer> uniqueNums = new ArrayList<>(m.keySet());\n        \n        for (int count : m.values()) {\n            ans += (count * (count - 1)) / 2;\n        }\n\n        int n = uniqueNums.size();\n        for (int i = 0; i < n; i++) {\n            for (int j = i + 1; j < n; j++) {\n                if (ist(uniqueNums.get(i), uniqueNums.get(j))) {\n                    ans += (m.get(uniqueNums.get(i)) * m.get(uniqueNums.get(j)));\n                }\n            }\n        }\n\n        return ans;\n    }\n}\n\n```
['String', 'Java']