Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1d3dd98

Browse files
Strong Password Checker II
1 parent 931d906 commit 1d3dd98

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Link: https://leetcode.com/problems/strong-password-checker-ii/
2+
Language: C#
3+
4+
5+
6+
7+
8+
public class Solution {
9+
public bool StrongPasswordCheckerII(string password)
10+
{
11+
if (password.Length < 8) return false;
12+
13+
string specialChars = "!@#$%^&*()-+";
14+
bool special = false;
15+
bool digit = false;
16+
bool upper = false;
17+
bool lower = false;
18+
19+
for (int i = 0; i < password.Length; i++)
20+
{
21+
if (i > 0 && password[i] == password[i - 1])
22+
return false;
23+
if (char.IsDigit(password[i]))
24+
digit = true;
25+
else if (char.IsUpper(password[i]))
26+
upper = true;
27+
else if (char.IsLower(password[i]))
28+
lower = true;
29+
else if (specialChars.Contains(password[i]))
30+
special = true;
31+
}
32+
33+
return special && digit && upper && lower;
34+
}
35+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /