Skip to content

Commit 586546b

Browse files
committedJan 19, 2023
2299. 强密码检验器 II
1 parent 864ff08 commit 586546b

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed
 

‎README.md

+1
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@
185185
|2283|[判断一个数的数字计数是否等于数位的值](https://leetcode.cn/problems/check-if-number-has-equal-digit-count-and-digit-value/)|[JavaScript](./algorithms/check-if-number-has-equal-digit-count-and-digit-value.js)|Easy|
186186
|2287|[重排字符形成目标字符串](https://leetcode.cn/problems/rearrange-characters-to-make-target-string/)|[JavaScript](./algorithms/rearrange-characters-to-make-target-string.js)|Easy|
187187
|2293|[极大极小游戏](https://leetcode.cn/problems/min-max-game/)|[JavaScript](./algorithms/min-max-game.js)|Easy|
188+
|2299|[强密码检验器 II](https://leetcode.cn/problems/strong-password-checker-ii/)|[JavaScript](./algorithms/strong-password-checker-ii.js)|Easy|
188189
|面试题 04.12|[面试题 04.12. 求和路径](https://leetcode.cn/problems/paths-with-sum-lcci/)|[JavaScript](./algorithms/paths-with-sum-lcci.js)|Medium|
189190
|面试题 02.07|[面试题 02.07. 链表相交](https://leetcode.cn/problems/intersection-of-two-linked-lists-lcci/)|[JavaScript](./algorithms/intersection-of-two-linked-lists-lcci.js)|Easy|
190191
|剑指 Offer 05. 替换空格|[剑指 Offer 05. 替换空格](https://leetcode.cn/problems/ti-huan-kong-ge-lcof/)|[JavaScript](./algorithms/ti-huan-kong-ge-lcof.js)|Easy|
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/**
2+
* 2299. 强密码检验器 II
3+
* @param {string} password
4+
* @return {boolean}
5+
*/
6+
var strongPasswordCheckerII = function (password) {
7+
if (password.length < 8) return false;
8+
let lowerCaseFlag = false;
9+
let upperCaseFlag = false;
10+
let digitFlag = false;
11+
let specialCharFlag = false;
12+
13+
const isLowerCase = (c) => c >= "a" && c <= "z";
14+
const isUpperCase = (c) => c >= "A" && c <= "Z";
15+
const isNumber = (c) => c >= "0" && c <= "9";
16+
const specialSet = new Set("!@#$%^&*()-+");
17+
18+
let perv = "";
19+
20+
for (let i = 0; i < password.length; i++) {
21+
let char = password[i];
22+
23+
if (perv === char) {
24+
return false;
25+
}
26+
perv = char;
27+
28+
if (isLowerCase(char)) {
29+
lowerCaseFlag = true;
30+
}
31+
if (isUpperCase(char)) {
32+
upperCaseFlag = true;
33+
}
34+
if (isNumber(char)) {
35+
digitFlag = true;
36+
}
37+
if (!specialCharFlag && specialSet.has(char)) {
38+
specialCharFlag = true;
39+
}
40+
}
41+
42+
return lowerCaseFlag && upperCaseFlag && digitFlag && specialCharFlag;
43+
};

0 commit comments

Comments
 (0)
Please sign in to comment.