2309. 兼具大小写的最好英文字母
为保证权益,题目请参考 2309. 兼具大小写的最好英文字母(From LeetCode).
解决方案1
CPP
C++
#include <iostream>
#include <map>
#include <memory>
#include <string>
using namespace std;
class Solution {
public:
string greatestLetter(string s) {
auto betterLetter = make_unique<int[]>(26);
for (int i = 0; i < 26; i++) {
betterLetter[i] = 0;
}
for (const char& ch : s) {
if (isupper(ch) && betterLetter[ch - 'A'] / 10 != 1) {
betterLetter[ch - 'A'] += 10;
} else if (islower(ch) && betterLetter[ch - 'a'] % 10 != 1) {
betterLetter[ch - 'a'] += 1;
}
}
for (int i = 25; i >= 0; i--) {
if (betterLetter[i] == 11) {
string ans = "";
ans.push_back(char(i + 'A'));
return ans;
}
}
return "";
}
};
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
30
31
32
33
34
35
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
30
31
32
33
34
35