Count Words Obtained After Adding a Letter LeetCode solution in C++
1class Solution {2public:3int wordCount(vector<string> &startWords, vector<string> &targetWords) {4set<vector<int>> hash;5for (int i = 0; i < startWords.size(); i++) {6vector<int> counter(26, 0);7for (char &x : startWords[i]) {8counter[x - 'a']++;9}10hash.insert(counter);11}1213int ans = 0;1415for (int i = 0; i < targetWords.size(); i++) {16vector<int> counter(26, 0);17for (char &x : targetWords[i]) {18counter[x - 'a']++;19}2021for (int j = 0; j < 26; j++) {22if (counter[j] == 1) {23counter[j] = 0;2425if (hash.find(counter) != hash.end()) {26ans++;27break;28}2930counter[j] = 1;31}32}33}3435return ans;36}37};