Java HashMap Sort
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\n        List<Set<Integer>> list = new ArrayList<Set<Integer>>();\n\n        Arrays.sort(nums);\n        for(int i = 0; i < nums.length; i++) list.add(new HashSet<Integer>());\n\n        Map<Integer, Integer> map = new HashMap<Integer, Integer>();\n\n        for(int i = 0; i < nums.length; i++) {\n            map.put(nums[i], map.getOrDefault(nums[i], 0)+1);\n            char c1[] = String.valueOf(nums[i]).toCharArray();\n            list.get(i).add(nums[i]);\n            for(int a = 0; a < c1.length; a++) {\n                for(int b = a; b < c1.length; b++) {\n                    swap(c1,a,b);\n                    int num = 0;\n                    int de = 1;\n                    for(int k = c1.length-1; k >= 0; k--) {\n                        num +=  de * (int)(c1[k]-\'0\');\n                        de *= 10;\n                    }\n                    list.get(i).add(num);\n\n                    for(int c = 0; c < c1.length; c++) {\n                        for(int d = 0; d < c1.length; d++) {\n                            swap(c1,c,d);\n                            num = 0;\n                            de = 1;\n                            for(int k = c1.length-1; k >= 0; k--) {\n                                num +=  de * (int)(c1[k]-\'0\');\n                                de *= 10;\n                            }\n                            list.get(i).add(num);\n                            swap(c1,c,d);\n                        }\n                    }\n                    swap(c1,a,b);\n                }\n            }\n        }\n\n\n        int result = 0;\n\n        \n        // System.out.println(map);\n        for(int i = nums.length-1 ; i >= 0; i--) {\n            // System.out.println(list.get(i));\n            for(int key : list.get(i) ) {\n                result += map.getOrDefault(key,0);\n            }\n            result--;\n            int cnt = map.get(nums[i]);\n            if ( cnt == 1 ) map.remove(nums[i]);\n            else map.put(nums[i], cnt-1);\n        }\n\n        return result;\n    }\n\n    private void swap(char c[], int a, int b) {\n        char temp = c[a];\n        c[a] = c[b];\n        c[b] = temp;\n    }\n}\n```
['Hash Table', 'Sorting', 'Java']