-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path748.cpp
More file actions
29 lines (29 loc) · 880 Bytes
/
Copy path748.cpp
File metadata and controls
29 lines (29 loc) · 880 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Solution {
public:
string shortestCompletingWord(string licensePlate, vector<string> &words) {
string ret;
int minLen = INT_MAX;
unordered_map<char, int> letters;
for (char l : licensePlate)
if ((l >= 'a' && l <= 'z') || (l >= 'A' && l <= 'Z'))
++letters[tolower(l)];
for (const string &w: words) {
auto len = w.size();
if (len >= minLen) continue;
auto temp = letters;
for (const char &c:w) {
if (temp.find(c) != temp.end()) {
--temp[c];
if (!temp[c])
temp.erase(c);
} else
continue;
}
if (temp.empty()) {
ret = w;
minLen = len;
}
}
return ret;
}
};