2299. Strong Password Checker II 發表於 2023-02-13 | 分類於 leetcode problemsolution1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253class 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; }};