Skip to content

Commit df9d64c

Browse files
committed
feat: update solutions to lc problem: No.0916
1 parent e9864a1 commit df9d64c

File tree

4 files changed

+78
-78
lines changed

4 files changed

+78
-78
lines changed

solution/0900-0999/0916.Word Subsets/README.md

+26-26
Original file line numberDiff line numberDiff line change
@@ -229,27 +229,27 @@ func wordSubsets(words1 []string, words2 []string) (ans []string) {
229229

230230
```ts
231231
function wordSubsets(words1: string[], words2: string[]): string[] {
232-
const hash2 = new Map<string, number>();
232+
const cnt2 = new Map<string, number>();
233233

234-
for (const w of words2) {
235-
const hash = new Map<string, number>();
236-
for (const ch of w) {
237-
hash.set(ch, (hash.get(ch) ?? 0) + 1);
234+
for (const b of words2) {
235+
const cnt = new Map<string, number>();
236+
for (const c of b) {
237+
cnt.set(c, (cnt.get(c) ?? 0) + 1);
238238
}
239239

240-
for (const [k, v] of hash) {
241-
hash2.set(k, Math.max(hash2.get(k) ?? 0, v));
240+
for (const [k, v] of cnt) {
241+
cnt2.set(k, Math.max(cnt2.get(k) ?? 0, v));
242242
}
243243
}
244244

245-
return words1.filter(w => {
246-
const hash1 = new Map<string, number>();
247-
for (const ch of w) {
248-
hash1.set(ch, (hash1.get(ch) ?? 0) + 1);
245+
return words1.filter(a => {
246+
const cnt1 = new Map<string, number>();
247+
for (const c of a) {
248+
cnt1.set(c, (cnt1.get(c) ?? 0) + 1);
249249
}
250250

251-
for (const [k, v] of hash2) {
252-
if ((hash1.get(k) ?? 0) < v) return false;
251+
for (const [k, v] of cnt2) {
252+
if ((cnt1.get(k) ?? 0) < v) return false;
253253
}
254254

255255
return true;
@@ -261,27 +261,27 @@ function wordSubsets(words1: string[], words2: string[]): string[] {
261261

262262
```js
263263
function wordSubsets(words1, words2) {
264-
const hash2 = new Map();
264+
const cnt2 = new Map();
265265

266-
for (const w of words2) {
267-
const hash = new Map();
268-
for (const ch of w) {
269-
hash.set(ch, (hash.get(ch) ?? 0) + 1);
266+
for (const b of words2) {
267+
const cnt = new Map();
268+
for (const c of b) {
269+
cnt.set(c, (cnt.get(c) ?? 0) + 1);
270270
}
271271

272-
for (const [k, v] of hash) {
273-
hash2.set(k, Math.max(hash2.get(k) ?? 0, v));
272+
for (const [k, v] of cnt) {
273+
cnt2.set(k, Math.max(cnt2.get(k) ?? 0, v));
274274
}
275275
}
276276

277-
return words1.filter(w => {
278-
const hash1 = new Map();
279-
for (const ch of w) {
280-
hash1.set(ch, (hash1.get(ch) ?? 0) + 1);
277+
return words1.filter(a => {
278+
const cnt1 = new Map();
279+
for (const c of a) {
280+
cnt1.set(c, (cnt1.get(c) ?? 0) + 1);
281281
}
282282

283-
for (const [k, v] of hash2) {
284-
if ((hash1.get(k) ?? 0) < v) return false;
283+
for (const [k, v] of cnt2) {
284+
if ((cnt1.get(k) ?? 0) < v) return false;
285285
}
286286

287287
return true;

solution/0900-0999/0916.Word Subsets/README_EN.md

+26-26
Original file line numberDiff line numberDiff line change
@@ -213,27 +213,27 @@ func wordSubsets(words1 []string, words2 []string) (ans []string) {
213213

214214
```ts
215215
function wordSubsets(words1: string[], words2: string[]): string[] {
216-
const hash2 = new Map<string, number>();
216+
const cnt2 = new Map<string, number>();
217217

218-
for (const w of words2) {
219-
const hash = new Map<string, number>();
220-
for (const ch of w) {
221-
hash.set(ch, (hash.get(ch) ?? 0) + 1);
218+
for (const b of words2) {
219+
const cnt = new Map<string, number>();
220+
for (const c of b) {
221+
cnt.set(c, (cnt.get(c) ?? 0) + 1);
222222
}
223223

224-
for (const [k, v] of hash) {
225-
hash2.set(k, Math.max(hash2.get(k) ?? 0, v));
224+
for (const [k, v] of cnt) {
225+
cnt2.set(k, Math.max(cnt2.get(k) ?? 0, v));
226226
}
227227
}
228228

229-
return words1.filter(w => {
230-
const hash1 = new Map<string, number>();
231-
for (const ch of w) {
232-
hash1.set(ch, (hash1.get(ch) ?? 0) + 1);
229+
return words1.filter(a => {
230+
const cnt1 = new Map<string, number>();
231+
for (const c of a) {
232+
cnt1.set(c, (cnt1.get(c) ?? 0) + 1);
233233
}
234234

235-
for (const [k, v] of hash2) {
236-
if ((hash1.get(k) ?? 0) < v) return false;
235+
for (const [k, v] of cnt2) {
236+
if ((cnt1.get(k) ?? 0) < v) return false;
237237
}
238238

239239
return true;
@@ -245,27 +245,27 @@ function wordSubsets(words1: string[], words2: string[]): string[] {
245245

246246
```js
247247
function wordSubsets(words1, words2) {
248-
const hash2 = new Map();
248+
const cnt2 = new Map();
249249

250-
for (const w of words2) {
251-
const hash = new Map();
252-
for (const ch of w) {
253-
hash.set(ch, (hash.get(ch) ?? 0) + 1);
250+
for (const b of words2) {
251+
const cnt = new Map();
252+
for (const c of b) {
253+
cnt.set(c, (cnt.get(c) ?? 0) + 1);
254254
}
255255

256-
for (const [k, v] of hash) {
257-
hash2.set(k, Math.max(hash2.get(k) ?? 0, v));
256+
for (const [k, v] of cnt) {
257+
cnt2.set(k, Math.max(cnt2.get(k) ?? 0, v));
258258
}
259259
}
260260

261-
return words1.filter(w => {
262-
const hash1 = new Map();
263-
for (const ch of w) {
264-
hash1.set(ch, (hash1.get(ch) ?? 0) + 1);
261+
return words1.filter(a => {
262+
const cnt1 = new Map();
263+
for (const c of a) {
264+
cnt1.set(c, (cnt1.get(c) ?? 0) + 1);
265265
}
266266

267-
for (const [k, v] of hash2) {
268-
if ((hash1.get(k) ?? 0) < v) return false;
267+
for (const [k, v] of cnt2) {
268+
if ((cnt1.get(k) ?? 0) < v) return false;
269269
}
270270

271271
return true;

solution/0900-0999/0916.Word Subsets/Solution.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
function wordSubsets(words1, words2) {
2-
const hash2 = new Map();
2+
const cnt2 = new Map();
33

4-
for (const w of words2) {
5-
const hash = new Map();
6-
for (const ch of w) {
7-
hash.set(ch, (hash.get(ch) ?? 0) + 1);
4+
for (const b of words2) {
5+
const cnt = new Map();
6+
for (const c of b) {
7+
cnt.set(c, (cnt.get(c) ?? 0) + 1);
88
}
99

10-
for (const [k, v] of hash) {
11-
hash2.set(k, Math.max(hash2.get(k) ?? 0, v));
10+
for (const [k, v] of cnt) {
11+
cnt2.set(k, Math.max(cnt2.get(k) ?? 0, v));
1212
}
1313
}
1414

15-
return words1.filter(w => {
16-
const hash1 = new Map();
17-
for (const ch of w) {
18-
hash1.set(ch, (hash1.get(ch) ?? 0) + 1);
15+
return words1.filter(a => {
16+
const cnt1 = new Map();
17+
for (const c of a) {
18+
cnt1.set(c, (cnt1.get(c) ?? 0) + 1);
1919
}
2020

21-
for (const [k, v] of hash2) {
22-
if ((hash1.get(k) ?? 0) < v) return false;
21+
for (const [k, v] of cnt2) {
22+
if ((cnt1.get(k) ?? 0) < v) return false;
2323
}
2424

2525
return true;

solution/0900-0999/0916.Word Subsets/Solution.ts

+13-13
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11
function wordSubsets(words1: string[], words2: string[]): string[] {
2-
const hash2 = new Map<string, number>();
2+
const cnt2 = new Map<string, number>();
33

4-
for (const w of words2) {
5-
const hash = new Map<string, number>();
6-
for (const ch of w) {
7-
hash.set(ch, (hash.get(ch) ?? 0) + 1);
4+
for (const b of words2) {
5+
const cnt = new Map<string, number>();
6+
for (const c of b) {
7+
cnt.set(c, (cnt.get(c) ?? 0) + 1);
88
}
99

10-
for (const [k, v] of hash) {
11-
hash2.set(k, Math.max(hash2.get(k) ?? 0, v));
10+
for (const [k, v] of cnt) {
11+
cnt2.set(k, Math.max(cnt2.get(k) ?? 0, v));
1212
}
1313
}
1414

15-
return words1.filter(w => {
16-
const hash1 = new Map<string, number>();
17-
for (const ch of w) {
18-
hash1.set(ch, (hash1.get(ch) ?? 0) + 1);
15+
return words1.filter(a => {
16+
const cnt1 = new Map<string, number>();
17+
for (const c of a) {
18+
cnt1.set(c, (cnt1.get(c) ?? 0) + 1);
1919
}
2020

21-
for (const [k, v] of hash2) {
22-
if ((hash1.get(k) ?? 0) < v) return false;
21+
for (const [k, v] of cnt2) {
22+
if ((cnt1.get(k) ?? 0) < v) return false;
2323
}
2424

2525
return true;

0 commit comments

Comments
 (0)