-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStrongPasswordChecker.java
More file actions
25 lines (22 loc) · 1.03 KB
/
Copy pathStrongPasswordChecker.java
File metadata and controls
25 lines (22 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package LeetcodePractice;
public class StrongPasswordChecker {
public static boolean strongPasswordCheckerII(String password) {
if (password.length() < 8) return false;
boolean hasLower = false, hasUpper = false, hasDigit = false, hasSpecial = false;
String special = "!@#$%^&*()-+";
for (int i = 0; i < password.length(); i++) {
char c = password.charAt(i);
if (i > 0 && c == password.charAt(i - 1)) return false;
if (Character.isLowerCase(c)) hasLower = true;
if (Character.isUpperCase(c)) hasUpper = true;
if (Character.isDigit(c)) hasDigit = true;
if (special.indexOf(c) != -1) hasSpecial = true;
}
return hasLower && hasUpper && hasDigit && hasSpecial;
}
public static void main(String[] args) {
System.out.println(strongPasswordCheckerII("IloveLe3tcode!"));
System.out.println(strongPasswordCheckerII("Me+You--IsMyDream"));
System.out.println(strongPasswordCheckerII("1aB!"));
}
}