Given an array of digit strings nums and a digit string target, return the number of pairs of indices (i, j) (where i != j) such that the concatenation of nums[i] + nums[j] equals target.
1 2 3 4 5 6 7 8 9 10 11 12 13
classSolution { public: intnumOfPairs(vector<string>& A, string target){ unordered_map<string, int> freq; for(auto& a : A) freq[a]++; int res = 0; for(int i = 1; i < target.length(); i++) { string a = target.substr(0,i), b = target.substr(i); res += freq[a] * (freq[b] - (a == b)); } return res; } };