1
class Solution {
2
public boolean strongPasswordCheckerII(String password) {
3
HashSet<Integer> intAscii = new HashSet<>();
4
String specialCharacters = "!@#$%^&*()-+";
5
for (int i = 0; i < specialCharacters.length(); i++) {
6
int ascii = specialCharacters.charAt(i);
7
intAscii.add(ascii);
8
}
9

10
if (password.length() < 8) {
11
return false;
12
}
13
boolean small = false;
14
boolean large = false;
15
boolean numbers = false;
16
boolean specialChars = false;
17
for (int i = 0; i < password.length(); i++) {
18
int ascii = (int) (password.charAt(i));
19
if (ascii <= 90 && ascii >= 65) {
20
large = true;
21
}
22
if (ascii <= 122 && ascii >= 97) {
23
small = true;
24
}
25
if (ascii <= 57 && ascii >= 48) {
26
numbers = true;
27
}
28
if (intAscii.contains(ascii)) {
29
specialChars = true;
30
}
31
if (i > 0 && password.charAt(i) == password.charAt(i - 1)) {
32
return false;
33
}
34
}
35
if (large == false || small == false || numbers == false || specialChars == false) {
36
return false;
37
}
38
return true;
39
}
40
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0