0%

824. Goat Latin

O(n) time

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class Solution {
public:
string toGoatLatin(string S) {
istringstream input(S);
string res, s;
int i = 0;
unordered_set<char> vowel = {'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};
while (input >> s) {
if (!vowel.count(s[0])) {
s += s[0];
s.erase(0, 1);
}
s += "ma";
s.append(++i, 'a');
res += s;
res += " ";
}
res.pop_back();
return res;
}
};