Greatest English Letter in Upper and Lower Case LeetCode solution in C++

1
class Solution {
2
public:
3
string greatestLetter(string s) {
4
vector<int> low(26),
5
upp(26); // storing occurences of lower and upper case letters
6
string res = "";
7

8
for (auto it : s) // iterate over each char and mark it in respective vector
9
{
10
if (it - 'A' >= 0 && it - 'A' < 26)
11
upp[it - 'A']++;
12
else
13
low[it - 'a']++;
14
}
15

16
for (int i = 25; i >= 0; i--) // start from greater char
17
{
18
if (low[i] && upp[i]) // if char found in upp and low that will be the result
19
{
20
res += 'A' + i;
21
break;
22
}
23
}
24
return res;
25
}
26
};

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0