Skip to content

Commit e8cb9f5

Browse files
authored
feat: add solutions to lc problems: No.1096, 1616 (doocs#917)
* No.1096.Brace Expansion II * No.1616.Split Two Strings to Make Palindrome
1 parent 014bbc3 commit e8cb9f5

File tree

6 files changed

+144
-0
lines changed

6 files changed

+144
-0
lines changed

solution/1000-1099/1096.Brace Expansion II/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,32 @@ func braceExpansionII(expression string) []string {
198198
}
199199
```
200200

201+
### **TypeScript**
202+
203+
```ts
204+
function braceExpansionII(expression: string): string[] {
205+
const dfs = (exp: string) => {
206+
let j = exp.indexOf('}');
207+
if (j === -1) {
208+
s.add(exp);
209+
return;
210+
}
211+
let i = j;
212+
while (exp.charAt(i) !== '{') {
213+
--i;
214+
}
215+
let a = exp.substring(0, i);
216+
let c = exp.substring(j + 1);
217+
for (const b of exp.substring(i + 1, j).split(',')) {
218+
dfs(a + b + c);
219+
}
220+
};
221+
const s: Set<string> = new Set();
222+
dfs(expression);
223+
return Array.from(s).sort();
224+
}
225+
```
226+
201227
### **...**
202228

203229
```

solution/1000-1099/1096.Brace Expansion II/README_EN.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,32 @@ func braceExpansionII(expression string) []string {
177177
}
178178
```
179179

180+
### **TypeScript**
181+
182+
```ts
183+
function braceExpansionII(expression: string): string[] {
184+
const dfs = (exp: string) => {
185+
let j = exp.indexOf('}');
186+
if (j === -1) {
187+
s.add(exp);
188+
return;
189+
}
190+
let i = j;
191+
while (exp.charAt(i) !== '{') {
192+
--i;
193+
}
194+
let a = exp.substring(0, i);
195+
let c = exp.substring(j + 1);
196+
for (const b of exp.substring(i + 1, j).split(',')) {
197+
dfs(a + b + c);
198+
}
199+
};
200+
const s: Set<string> = new Set();
201+
dfs(expression);
202+
return Array.from(s).sort();
203+
}
204+
```
205+
180206
### **...**
181207

182208
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
function braceExpansionII(expression: string): string[] {
2+
const dfs = (exp: string) => {
3+
let j = exp.indexOf('}');
4+
if (j === -1) {
5+
s.add(exp);
6+
return;
7+
}
8+
let i = j;
9+
while (exp.charAt(i) !== '{') {
10+
--i;
11+
}
12+
let a = exp.substring(0, i);
13+
let c = exp.substring(j + 1);
14+
for (const b of exp.substring(i + 1, j).split(',')) {
15+
dfs(a + b + c);
16+
}
17+
};
18+
const s: Set<string> = new Set();
19+
dfs(expression);
20+
return Array.from(s).sort();
21+
}

solution/1600-1699/1616.Split Two Strings to Make Palindrome/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,32 @@ impl Solution {
203203
}
204204
```
205205

206+
### **TypeScript**
207+
208+
```ts
209+
function checkPalindromeFormation(a: string, b: string): boolean {
210+
const check1 = (a: string, b: string) => {
211+
let i = 0;
212+
let j = b.length - 1;
213+
while (i < j && a.charAt(i) === b.charAt(j)) {
214+
i++;
215+
j--;
216+
}
217+
return i >= j || check2(a, i, j) || check2(b, i, j);
218+
};
219+
220+
const check2 = (a: string, i: number, j: number) => {
221+
while (i < j && a.charAt(i) === a.charAt(j)) {
222+
i++;
223+
j--;
224+
}
225+
return i >= j;
226+
};
227+
return check1(a, b) || check1(b, a);
228+
}
229+
230+
```
231+
206232
### **...**
207233

208234
```

solution/1600-1699/1616.Split Two Strings to Make Palindrome/README_EN.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,31 @@ impl Solution {
186186
}
187187
```
188188

189+
### **TypeScript**
190+
191+
```ts
192+
function checkPalindromeFormation(a: string, b: string): boolean {
193+
const check1 = (a: string, b: string) => {
194+
let i = 0;
195+
let j = b.length - 1;
196+
while (i < j && a.charAt(i) === b.charAt(j)) {
197+
i++;
198+
j--;
199+
}
200+
return i >= j || check2(a, i, j) || check2(b, i, j);
201+
};
202+
203+
const check2 = (a: string, i: number, j: number) => {
204+
while (i < j && a.charAt(i) === a.charAt(j)) {
205+
i++;
206+
j--;
207+
}
208+
return i >= j;
209+
};
210+
return check1(a, b) || check1(b, a);
211+
}
212+
```
213+
189214
### **...**
190215

191216
```
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
function checkPalindromeFormation(a: string, b: string): boolean {
2+
const check1 = (a: string, b: string) => {
3+
let i = 0;
4+
let j = b.length - 1;
5+
while (i < j && a.charAt(i) === b.charAt(j)) {
6+
i++;
7+
j--;
8+
}
9+
return i >= j || check2(a, i, j) || check2(b, i, j);
10+
};
11+
12+
const check2 = (a: string, i: number, j: number) => {
13+
while (i < j && a.charAt(i) === a.charAt(j)) {
14+
i++;
15+
j--;
16+
}
17+
return i >= j;
18+
};
19+
return check1(a, b) || check1(b, a);
20+
}

0 commit comments

Comments
 (0)