1
class Solution {
2
public:
3
string shortestCompletingWord(string licensePlate, vector<string> &words) {
4
string ans = "";
5
vector<int> m(26, 0);
6
for (auto &lp : licensePlate) {
7
if (isalpha(lp)) m[tolower(lp) - 'a']++;
8
}
9
for (auto &word : words) {
10
vector<int> v = m;
11
for (auto &ch : word) {
12
v[tolower(ch) - 'a']--;
13
}
14
bool flag = true;
15
for (int i = 0; i < 26; i++) {
16
if (v[i] > 0) flag = false;
17
}
18
if (flag && (ans == "" || ans.size() > word.size())) ans = word;
19
}
20
return ans;
21
}
22
};
23
// if you like the solution plz upvote.

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0