-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2299.强密码检验器-ii.js
More file actions
49 lines (47 loc) · 1.07 KB
/
2299.强密码检验器-ii.js
File metadata and controls
49 lines (47 loc) · 1.07 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
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
/*
* @lc app=leetcode.cn id=2299 lang=javascript
*
* [2299] 强密码检验器 II
*/
// @lc code=start
/**
* @param {string} password
* @return {boolean}
*/
var strongPasswordCheckerII = function (password) {
let isUpperCase = false,
isLowerCase = false,
isHaveNum = false,
isHaveSpecial = false;
if (password.length < 8) return false;
for (let i = 0; i < password.length; i++) {
if (!isUpperCase) {
if ("A" <= password[i] && password[i] <= "Z") {
isUpperCase = true;
}
}
if (!isLowerCase) {
if ("a" <= password[i] && password[i] <= "z") {
isLowerCase = true;
}
}
if (!isHaveNum) {
if (
!isNaN(Number(password[i])) &&
typeof Number(password[i]) === "number"
) {
isHaveNum = true;
}
}
if (!isHaveSpecial) {
if ("!@#$%^&*()-+".includes(password[i])) {
isHaveSpecial = true;
}
}
if (password[i] === password[i + 1]) {
return false;
}
}
return isUpperCase && isLowerCase && isHaveNum && isHaveSpecial;
};
// @lc code=end