2299. Strong Password Checker II
Question
A password is said to be strong if it satisfies all the following criteria:
It has at least
8
characters.It contains at least one lowercase letter.
It contains at least one uppercase letter.
It contains at least one digit.
It contains at least one special character. The special characters are the characters in the following string:
"!@#$%^&*()-+"
.It does not contain
2
of the same character in adjacent positions (i.e.,"aab"
violates this condition, but"aba"
does not).Given a string
password
, returntrue
* if it is a strong password*. Otherwise, returnfalse
.
Solution
直接遍历,记录四个真值对应四个符号,初始化为false,和上一个字符last。
每次遍历检查当前字符,如果等于上个字符则直接返回false。
根据字符范围来改变四个真值,最后返回四个真值的和运算。
Code
1 | class Solution { |
2299. Strong Password Checker II
https://xuanhe95.github.io/2022/06/12/2299-Strong-Password-Checker-II/