Beats 100% JAVA
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:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```java []\nclass Solution {\n    public int countPairs(int[] nums) {\n        int n = nums.length;\n        String[] strs = new String[n];\n\t\t\n\t\tint result = 0;\n        Map<String, List<Integer>> map = new HashMap();\n        for (int i = 0; i < n; i++) {\n        \tint now = nums[i];\n        \tString str = now + "";\n        \twhile (str.length() < 7)\n        \t\tstr = "0" + str;\n        \tstrs[i] = str;\n        \tchar[] chars = str.toCharArray();\n        \tArrays.sort(chars);\n        \tString key = new String(chars);\n        \tif (!map.containsKey(key))\n        \t\tmap.put(key, new ArrayList());\n        \tmap.get(key).add(i);\n        }\n        for (List<Integer> list : map.values()) {\n\t        for (int i = 1; i < list.size(); i++) {\n\t        \tfor (int j = 0; j < i; j++) {\n\t        \t\tif (check(strs[list.get(i)], strs[list.get(j)]))\n\t        \t\t\tresult++;\n\t        \t}\n\t        }\n        }\n        return result;\n    }\n\t\n\tprivate static boolean check(String a, String b) {\n\t\tList<Integer> list = new ArrayList();\n\t\tfor (int i = 0; i < a.length(); i++) {\n\t\t\tif (a.charAt(i) != b.charAt(i))\n\t\t\t\tlist.add(i);\n\t\t}\n\t\tif (list.size() == 1 || list.size() > 4)\n\t\t\treturn false;\n\t\tif (list.size() < 4)\n\t\t\treturn true;\n\t\tif (check(a, b, list, 0, 1))\n\t\t\treturn true;\n\t\tif (check(a, b, list, 0, 2))\n\t\t\treturn true;\n\t\treturn (check(a, b, list, 0, 3));\n    }\n\t\n\tprivate static boolean check(String a, String b, List<Integer> list, int x, int y) {\n\t\treturn a.charAt(list.get(x)) == b.charAt(list.get(y)) && a.charAt(list.get(y)) == b.charAt(list.get(x));\n\t}\n}\n```
['Java']