2299. Strong Password Checker II

problem

solution

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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
class Solution {
public:
unordered_set<char> special = {
'!','@','#','$','%','^','&','*','(',')','-','+'
};
bool Rule1(string password){
return password.size()>7;
}
bool Rule2(string password){
for(char c:password){
if(c>='a' && c<='z') return true;
}
return false;
}
bool Rule3(string password){
for(char c:password){
if(c>='A' && c<='Z') return true;
}
return false;
}
bool Rule4(string password){
for(char c:password){
if(c>='0' && c<='9') return true;
}
return false;
}
bool Rule5(string password){
for(char c:password){
if(special.count(c)) return true;
}
return false;
}
bool Rule6(string password){
for(int i=1;i<password.size() ; ++i){
if(password[i] == password[i-1]) return false;
}
return true;
}


bool strongPasswordCheckerII(string password) {
bool ret = true;
ret &= Rule1(password);
ret &= Rule2(password);
ret &= Rule3(password);
ret &= Rule4(password);
ret &= Rule5(password);
ret &= Rule6(password);
return ret;


}
};