Easy Brute force Solution C++ Code
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```cpp []\nclass Solution {\npublic:\n    Solution() {\n       ios_base::sync_with_stdio(false);\n       cin.tie(nullptr);\n       cout.tie(nullptr);\n    }\n\n    unordered_set<int> getit(string &s) {\n       unordered_set<int> st;\n       for (int k = 0; k < s.size(); ++k) {\n          for (int l = k + 1; l < s.size(); ++l) {\n             string x = s;\n             swap(x[k], x[l]);\n             st.insert(stoi(x));\n             for (int i = 0; i < s.size(); ++i) {\n                for (int j = i + 1; j < s.size(); ++j) {\n                   string a = x;\n                   swap(a[i], a[j]);\n                   st.insert(stoi(a));\n                }\n             }\n          }\n       }\n       if (st.empty())st.insert(stoi(s));\n       return st;\n    }\n\n    int countPairs(vector<int> &nums) {\n       unordered_map<int, unordered_set<int>> v;\n       string sz = to_string(*max_element(nums.begin(), nums.end()));\n       for (int i = 0; i < nums.size(); ++i) {\n          string s = to_string(nums[i]);\n          while (s.size() < sz.size()) s = \'0\' + s;\n          v[nums[i]] = getit(s);\n       }\n       unordered_map<int, int> fre;\n       for (auto &it: nums) fre[it]++;\n       int ans = 0;\n       for (int i = 0; i < nums.size(); ++i) {\n          --fre[nums[i]];\n          for (auto &it: v[nums[i]])\n             ans += fre[it];\n       }\n       return ans;\n    }\n};\n```
['C++']