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 14322a7

Browse files
committed
feat: update solutions to lc problems
* No.2299.Strong Password Checker II * No.2306.Naming a Company
1 parent 3db68e2 commit 14322a7

File tree

14 files changed

+448
-124
lines changed

14 files changed

+448
-124
lines changed

‎solution/2200-2299/2298.Tasks Count in the Weekend/README.md‎

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,11 @@ Task 6 was submitted on Sunday.
7373

7474
<!-- tabs:start -->
7575

76-
### **Python3**
76+
### **SQL**
7777

7878
<!-- 这里可写当前语言的特殊实现逻辑 -->
7979

80-
```python
81-
82-
```
83-
84-
### **Java**
85-
86-
<!-- 这里可写当前语言的特殊实现逻辑 -->
87-
88-
```java
89-
90-
```
91-
92-
### **TypeScript**
93-
94-
```ts
95-
96-
```
97-
98-
### **...**
99-
100-
```
80+
```sql
10181

10282
```
10383

‎solution/2200-2299/2298.Tasks Count in the Weekend/README_EN.md‎

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -69,27 +69,9 @@ Task 6 was submitted on Sunday.
6969

7070
<!-- tabs:start -->
7171

72-
### **Python3**
72+
### **SQL**
7373

74-
```python
75-
76-
```
77-
78-
### **Java**
79-
80-
```java
81-
82-
```
83-
84-
### **TypeScript**
85-
86-
```ts
87-
88-
```
89-
90-
### **...**
91-
92-
```
74+
```sql
9375

9476
```
9577

‎solution/2200-2299/2299.Strong Password Checker II/README.md‎

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,16 @@ class Solution:
6969
if len(password) < 8:
7070
return False
7171
ans = 0
72-
prev = '.'
73-
for c in password:
74-
if prev == c:
72+
for i, c in enumerate(password):
73+
if i and password[i - 1] == c:
7574
return False
76-
prev = c
7775
if c.islower():
7876
ans |= 1
79-
if c.isupper():
77+
elif c.isupper():
8078
ans |= 2
81-
if c.isdigit():
79+
elif c.isdigit():
8280
ans |= 4
83-
if c in'!@#$%^&*()-+':
81+
else:
8482
ans |= 8
8583
return ans == 15
8684
```
@@ -104,14 +102,11 @@ class Solution {
104102
prev = c;
105103
if (Character.isLowerCase(c)) {
106104
ans |= 1;
107-
}
108-
if (Character.isUpperCase(c)) {
105+
} else if (Character.isUpperCase(c)) {
109106
ans |= 2;
110-
}
111-
if (Character.isDigit(c)) {
107+
} else if (Character.isDigit(c)) {
112108
ans |= 4;
113-
}
114-
if ("!@#$%^&*()-+".contains(c + "")) {
109+
} else {
115110
ans |= 8;
116111
}
117112
}
@@ -120,6 +115,55 @@ class Solution {
120115
}
121116
```
122117

118+
### **C++**
119+
120+
```cpp
121+
class Solution {
122+
public:
123+
bool strongPasswordCheckerII(string password) {
124+
if (password.size() < 8) return false;
125+
int ans = 0;
126+
char prev = '.';
127+
for (char& c : password)
128+
{
129+
if (c == prev) return false;
130+
prev = c;
131+
if (c >= 'a' && c <= 'z') ans |= 1;
132+
else if (c >= 'A' && c <= 'Z') ans |= 2;
133+
else if (c >= '0' && c <= '9') ans |= 4;
134+
else ans |= 8;
135+
}
136+
return ans == 15;
137+
}
138+
};
139+
```
140+
141+
### **Go**
142+
143+
```go
144+
func strongPasswordCheckerII(password string) bool {
145+
if len(password) < 8 {
146+
return false
147+
}
148+
ans := 0
149+
for i, c := range password {
150+
if i > 0 && password[i] == password[i-1] {
151+
return false
152+
}
153+
if unicode.IsLower(c) {
154+
ans |= 1
155+
} else if unicode.IsUpper(c) {
156+
ans |= 2
157+
} else if unicode.IsDigit(c) {
158+
ans |= 4
159+
} else {
160+
ans |= 8
161+
}
162+
}
163+
return ans == 15
164+
}
165+
```
166+
123167
### **TypeScript**
124168

125169
```ts

‎solution/2200-2299/2299.Strong Password Checker II/README_EN.md‎

Lines changed: 57 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,16 @@ class Solution:
6262
if len(password) < 8:
6363
return False
6464
ans = 0
65-
prev = '.'
66-
for c in password:
67-
if prev == c:
65+
for i, c in enumerate(password):
66+
if i and password[i - 1] == c:
6867
return False
69-
prev = c
7068
if c.islower():
7169
ans |= 1
72-
if c.isupper():
70+
elif c.isupper():
7371
ans |= 2
74-
if c.isdigit():
72+
elif c.isdigit():
7573
ans |= 4
76-
if c in'!@#$%^&*()-+':
74+
else:
7775
ans |= 8
7876
return ans == 15
7977
```
@@ -95,14 +93,11 @@ class Solution {
9593
prev = c;
9694
if (Character.isLowerCase(c)) {
9795
ans |= 1;
98-
}
99-
if (Character.isUpperCase(c)) {
96+
} else if (Character.isUpperCase(c)) {
10097
ans |= 2;
101-
}
102-
if (Character.isDigit(c)) {
98+
} else if (Character.isDigit(c)) {
10399
ans |= 4;
104-
}
105-
if ("!@#$%^&*()-+".contains(c + "")) {
100+
} else {
106101
ans |= 8;
107102
}
108103
}
@@ -111,6 +106,55 @@ class Solution {
111106
}
112107
```
113108

109+
### **C++**
110+
111+
```cpp
112+
class Solution {
113+
public:
114+
bool strongPasswordCheckerII(string password) {
115+
if (password.size() < 8) return false;
116+
int ans = 0;
117+
char prev = '.';
118+
for (char& c : password)
119+
{
120+
if (c == prev) return false;
121+
prev = c;
122+
if (c >= 'a' && c <= 'z') ans |= 1;
123+
else if (c >= 'A' && c <= 'Z') ans |= 2;
124+
else if (c >= '0' && c <= '9') ans |= 4;
125+
else ans |= 8;
126+
}
127+
return ans == 15;
128+
}
129+
};
130+
```
131+
132+
### **Go**
133+
134+
```go
135+
func strongPasswordCheckerII(password string) bool {
136+
if len(password) < 8 {
137+
return false
138+
}
139+
ans := 0
140+
for i, c := range password {
141+
if i > 0 && password[i] == password[i-1] {
142+
return false
143+
}
144+
if unicode.IsLower(c) {
145+
ans |= 1
146+
} else if unicode.IsUpper(c) {
147+
ans |= 2
148+
} else if unicode.IsDigit(c) {
149+
ans |= 4
150+
} else {
151+
ans |= 8
152+
}
153+
}
154+
return ans == 15
155+
}
156+
```
157+
114158
### **TypeScript**
115159

116160
```ts
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class Solution {
2+
public:
3+
bool strongPasswordCheckerII(string password) {
4+
if (password.size() < 8) return false;
5+
int ans = 0;
6+
char prev = '.';
7+
for (char& c : password)
8+
{
9+
if (c == prev) return false;
10+
prev = c;
11+
if (c >= 'a' && c <= 'z') ans |= 1;
12+
else if (c >= 'A' && c <= 'Z') ans |= 2;
13+
else if (c >= '0' && c <= '9') ans |= 4;
14+
else ans |= 8;
15+
}
16+
return ans == 15;
17+
}
18+
};
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
func strongPasswordCheckerII(password string) bool {
2+
if len(password) < 8 {
3+
return false
4+
}
5+
ans := 0
6+
for i, c := range password {
7+
if i > 0 && password[i] == password[i-1] {
8+
return false
9+
}
10+
if unicode.IsLower(c) {
11+
ans |= 1
12+
} else if unicode.IsUpper(c) {
13+
ans |= 2
14+
} else if unicode.IsDigit(c) {
15+
ans |= 4
16+
} else {
17+
ans |= 8
18+
}
19+
}
20+
return ans == 15
21+
}

‎solution/2200-2299/2299.Strong Password Checker II/Solution.java‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ public boolean strongPasswordCheckerII(String password) {
1212
prev = c;
1313
if (Character.isLowerCase(c)) {
1414
ans |= 1;
15-
}
16-
if (Character.isUpperCase(c)) {
15+
} else if (Character.isUpperCase(c)) {
1716
ans |= 2;
18-
}
19-
if (Character.isDigit(c)) {
17+
} else if (Character.isDigit(c)) {
2018
ans |= 4;
21-
}
22-
if ("!@#$%^&*()-+".contains(c + "")) {
19+
} else {
2320
ans |= 8;
2421
}
2522
}

‎solution/2200-2299/2299.Strong Password Checker II/Solution.py‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,15 @@ def strongPasswordCheckerII(self, password: str) -> bool:
33
if len(password) < 8:
44
return False
55
ans = 0
6-
prev = '.'
7-
for c in password:
8-
if prev == c:
6+
for i, c in enumerate(password):
7+
if i and password[i - 1] == c:
98
return False
10-
prev = c
119
if c.islower():
1210
ans |= 1
13-
if c.isupper():
11+
elif c.isupper():
1412
ans |= 2
15-
if c.isdigit():
13+
elif c.isdigit():
1614
ans |= 4
17-
ifcin'!@#$%^&*()-+':
15+
else:
1816
ans |= 8
1917
return ans == 15

0 commit comments

Comments
(0)

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