-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path3121.cpp
More file actions
29 lines (29 loc) · 762 Bytes
/
3121.cpp
File metadata and controls
29 lines (29 loc) · 762 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:
int numberOfSpecialChars(string word) {
bool lower[26];
bool upper[26];
bool valid[26];
for (int i = 0; i < 26; ++i) {
lower[i] = false;
upper[i] = false;
valid[i] = true;
}
for (auto& c : word) {
if (c >= 'a' && c <= 'z') {
lower[c - 'a'] = true;
if (upper[c - 'a']) {
valid[c - 'a'] = false;
}
}
if (c >= 'A' && c <= 'Z') {
upper[c - 'A'] = true;
}
}
int res = 0;
for (int i = 0; i < 26; ++i) {
if (lower[i] && upper[i] && valid[i]) res++;
}
return res;
}
};