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 23f6ec0

Browse files
feat: add ts solution to lc problem: No.1763
No.1763.Longest Nice Substring
1 parent 50a0092 commit 23f6ec0

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed

‎solution/1700-1799/1763.Longest Nice Substring/README.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,30 @@ class Solution {
109109

110110
```
111111

112+
### **TypeScript**
113+
114+
```ts
115+
function longestNiceSubstring(s: string): string {
116+
const n = s.length;
117+
let ans = '';
118+
for (let i = 0; i < n; i++) {
119+
let lower = 0, upper = 0;
120+
for (let j = i; j < n ; j++) {
121+
const c = s.charCodeAt(j);
122+
if (c > 96) {
123+
lower |= 1 << (c - 97);
124+
} else {
125+
upper |= 1 << (c - 65);
126+
}
127+
if (lower == upper && (j - i + 1) > ans.length) {
128+
ans = s.substring(i, j + 1);
129+
}
130+
}
131+
}
132+
return ans;
133+
};
134+
```
135+
112136
### **C++**
113137

114138
```cpp

‎solution/1700-1799/1763.Longest Nice Substring/README_EN.md‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,30 @@ class Solution {
9999

100100
```
101101

102+
### **TypeScript**
103+
104+
```ts
105+
function longestNiceSubstring(s: string): string {
106+
const n = s.length;
107+
let ans = '';
108+
for (let i = 0; i < n; i++) {
109+
let lower = 0, upper = 0;
110+
for (let j = i; j < n ; j++) {
111+
const c = s.charCodeAt(j);
112+
if (c > 96) {
113+
lower |= 1 << (c - 97);
114+
} else {
115+
upper |= 1 << (c - 65);
116+
}
117+
if (lower == upper && (j - i + 1) > ans.length) {
118+
ans = s.substring(i, j + 1);
119+
}
120+
}
121+
}
122+
return ans;
123+
};
124+
```
125+
102126
### **C++**
103127

104128
```cpp
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function longestNiceSubstring(s: string): string {
2+
const n = s.length;
3+
let ans = '';
4+
for (let i = 0; i < n; i++) {
5+
let lower = 0, upper = 0;
6+
for (let j = i; j < n ; j++) {
7+
const c = s.charCodeAt(j);
8+
if (c > 96) {
9+
lower |= 1 << (c - 97);
10+
} else {
11+
upper |= 1 << (c - 65);
12+
}
13+
if (lower == upper && (j - i + 1) > ans.length) {
14+
ans = s.substring(i, j + 1);
15+
}
16+
}
17+
}
18+
return ans;
19+
};

0 commit comments

Comments
(0)

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