-
Notifications
You must be signed in to change notification settings - Fork 0
/
StrongPasswordCheckerII.cpp
30 lines (27 loc) · 1.12 KB
/
StrongPasswordCheckerII.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
28
29
30
class Solution {
public:
bool strongPasswordCheckerII(string password) {
bool lowercase = false;
bool uppercase = false;
bool digit = false;
bool special = false;
if (password.size() < 8) {
return false;
}
for (int i = 0; i < password.size(); i++) {
if (password[i] >= 'a' && password[i] <= 'z') {
lowercase = true;
} else if (password[i] >= 'A' && password[i] <= 'Z') {
uppercase = true;
} else if (password[i] >= '0' && password[i] <= '9') {
digit = true;
} else if (password[i] != '!' || password[i] != '@' || password[i] == '#' || password[i] == '$' || password[i] == '%' || password[i] == '^' || password[i] == '&' || password[i] == '*' || password[i] == '(' || password[i] == ')' || password[i] == '-' || password[i] == '+') {
special = true;
}
if (i > 0 && password[i] == password[i-1]) {
return false;
}
}
return lowercase && uppercase && digit && special;
}
};