-
Notifications
You must be signed in to change notification settings - Fork 3
/
2299.cpp
27 lines (27 loc) · 953 Bytes
/
2299.cpp
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
class Solution {
public:
bool strongPasswordCheckerII(string password) {
// 8
if (password.size() < 8) return false;
unordered_set<char> hash;
string specials = "!@#$%^&*()-+";
for (auto& c : specials) hash.insert(c);
// one lowercase, uppercase, digit, special
bool lowercase = false;
bool uppercase = false;
bool digit = false;
bool special = false;
for (auto& c : password) {
if ('a' <= c && c <= 'z') lowercase = true;
if ('A' <= c && c <= 'Z') uppercase = true;
if ('0' <= c && c <= '9') digit = true;
if (hash.find(c) != hash.end()) special = true;
}
if (!lowercase || !uppercase || !digit || !special) return false;
// conse
for (int i = 0; i < password.size() - 1; ++i) {
if (password[i] == password[i + 1]) return false;
}
return true;
}
};