Skip to content

Commit 8cb01c7

Browse files
committed
feat: update solutions to lc problems: No.1096,1101
* No.1096.Brace Expansion II * No.1101.The Earliest Moment When Everyone Become Friends
1 parent f87a7aa commit 8cb01c7

File tree

10 files changed

+484
-177
lines changed

10 files changed

+484
-177
lines changed

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,7 @@ class Solution {
126126
s.add(exp);
127127
return;
128128
}
129-
int i = j;
130-
while (exp.charAt(i) != '{') {
131-
--i;
132-
}
129+
int i = exp.lastIndexOf('{', j);
133130
String a = exp.substring(0, i);
134131
String c = exp.substring(j + 1);
135132
for (String b : exp.substring(i + 1, j).split(",")) {
@@ -203,17 +200,14 @@ func braceExpansionII(expression string) []string {
203200
```ts
204201
function braceExpansionII(expression: string): string[] {
205202
const dfs = (exp: string) => {
206-
let j = exp.indexOf('}');
203+
const j = exp.indexOf('}');
207204
if (j === -1) {
208205
s.add(exp);
209206
return;
210207
}
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);
208+
const i = exp.lastIndexOf('{', j);
209+
const a = exp.substring(0, i);
210+
const c = exp.substring(j + 1);
217211
for (const b of exp.substring(i + 1, j).split(',')) {
218212
dfs(a + b + c);
219213
}

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

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,7 @@ class Solution {
105105
s.add(exp);
106106
return;
107107
}
108-
int i = j;
109-
while (exp.charAt(i) != '{') {
110-
--i;
111-
}
108+
int i = exp.lastIndexOf('{', j);
112109
String a = exp.substring(0, i);
113110
String c = exp.substring(j + 1);
114111
for (String b : exp.substring(i + 1, j).split(",")) {
@@ -182,17 +179,14 @@ func braceExpansionII(expression string) []string {
182179
```ts
183180
function braceExpansionII(expression: string): string[] {
184181
const dfs = (exp: string) => {
185-
let j = exp.indexOf('}');
182+
const j = exp.indexOf('}');
186183
if (j === -1) {
187184
s.add(exp);
188185
return;
189186
}
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);
187+
const i = exp.lastIndexOf('{', j);
188+
const a = exp.substring(0, i);
189+
const c = exp.substring(j + 1);
196190
for (const b of exp.substring(i + 1, j).split(',')) {
197191
dfs(a + b + c);
198192
}

solution/1000-1099/1096.Brace Expansion II/Solution.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@ private void dfs(String exp) {
1212
s.add(exp);
1313
return;
1414
}
15-
int i = j;
16-
while (exp.charAt(i) != '{') {
17-
--i;
18-
}
15+
int i = exp.lastIndexOf('{', j);
1916
String a = exp.substring(0, i);
2017
String c = exp.substring(j + 1);
2118
for (String b : exp.substring(i + 1, j).split(",")) {

solution/1000-1099/1096.Brace Expansion II/Solution.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
function braceExpansionII(expression: string): string[] {
22
const dfs = (exp: string) => {
3-
let j = exp.indexOf('}');
3+
const j = exp.indexOf('}');
44
if (j === -1) {
55
s.add(exp);
66
return;
77
}
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);
8+
const i = exp.lastIndexOf('{', j);
9+
const a = exp.substring(0, i);
10+
const c = exp.substring(j + 1);
1411
for (const b of exp.substring(i + 1, j).split(',')) {
1512
dfs(a + b + c);
1613
}

0 commit comments

Comments
 (0)