Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions solution/0900-0999/0916.Word Subsets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,94 @@ func wordSubsets(words1 []string, words2 []string) (ans []string) {
}
```

#### TypeScript

```ts
function wordSubsets(words1: string[], words2: string[]): string[] {
const cnt: number[] = Array(26).fill(0);
for (const b of words2) {
const t: number[] = Array(26).fill(0);
for (const c of b) {
t[c.charCodeAt(0) - 97]++;
}
for (let i = 0; i < 26; i++) {
cnt[i] = Math.max(cnt[i], t[i]);
}
}

const ans: string[] = [];
for (const a of words1) {
const t: number[] = Array(26).fill(0);
for (const c of a) {
t[c.charCodeAt(0) - 97]++;
}

let ok = true;
for (let i = 0; i < 26; i++) {
if (cnt[i] > t[i]) {
ok = false;
break;
}
}

if (ok) {
ans.push(a);
}
}

return ans;
}
```

#### JavaScript

```js
/**
* @param {string[]} words1
* @param {string[]} words2
* @return {string[]}
*/
var wordSubsets = function (words1, words2) {
const cnt = Array(26).fill(0);

for (const b of words2) {
const t = Array(26).fill(0);

for (const c of b) {
t[c.charCodeAt(0) - 97]++;
}

for (let i = 0; i < 26; i++) {
cnt[i] = Math.max(cnt[i], t[i]);
}
}

const ans = [];

for (const a of words1) {
const t = Array(26).fill(0);

for (const c of a) {
t[c.charCodeAt(0) - 97]++;
}

let ok = true;
for (let i = 0; i < 26; i++) {
if (cnt[i] > t[i]) {
ok = false;
break;
}
}

if (ok) {
ans.push(a);
}
}

return ans;
};
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
88 changes: 88 additions & 0 deletions solution/0900-0999/0916.Word Subsets/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,94 @@ func wordSubsets(words1 []string, words2 []string) (ans []string) {
}
```

#### TypeScript

```ts
function wordSubsets(words1: string[], words2: string[]): string[] {
const cnt: number[] = Array(26).fill(0);
for (const b of words2) {
const t: number[] = Array(26).fill(0);
for (const c of b) {
t[c.charCodeAt(0) - 97]++;
}
for (let i = 0; i < 26; i++) {
cnt[i] = Math.max(cnt[i], t[i]);
}
}

const ans: string[] = [];
for (const a of words1) {
const t: number[] = Array(26).fill(0);
for (const c of a) {
t[c.charCodeAt(0) - 97]++;
}

let ok = true;
for (let i = 0; i < 26; i++) {
if (cnt[i] > t[i]) {
ok = false;
break;
}
}

if (ok) {
ans.push(a);
}
}

return ans;
}
```

#### JavaScript

```js
/**
* @param {string[]} words1
* @param {string[]} words2
* @return {string[]}
*/
var wordSubsets = function (words1, words2) {
const cnt = Array(26).fill(0);

for (const b of words2) {
const t = Array(26).fill(0);

for (const c of b) {
t[c.charCodeAt(0) - 97]++;
}

for (let i = 0; i < 26; i++) {
cnt[i] = Math.max(cnt[i], t[i]);
}
}

const ans = [];

for (const a of words1) {
const t = Array(26).fill(0);

for (const c of a) {
t[c.charCodeAt(0) - 97]++;
}

let ok = true;
for (let i = 0; i < 26; i++) {
if (cnt[i] > t[i]) {
ok = false;
break;
}
}

if (ok) {
ans.push(a);
}
}

return ans;
};
```

<!-- tabs:end -->

<!-- solution:end -->
Expand Down
44 changes: 44 additions & 0 deletions solution/0900-0999/0916.Word Subsets/Solution.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* @param {string[]} words1
* @param {string[]} words2
* @return {string[]}
*/
var wordSubsets = function (words1, words2) {
const cnt = Array(26).fill(0);

for (const b of words2) {
const t = Array(26).fill(0);

for (const c of b) {
t[c.charCodeAt(0) - 97]++;
}

for (let i = 0; i < 26; i++) {
cnt[i] = Math.max(cnt[i], t[i]);
}
}

const ans = [];

for (const a of words1) {
const t = Array(26).fill(0);

for (const c of a) {
t[c.charCodeAt(0) - 97]++;
}

let ok = true;
for (let i = 0; i < 26; i++) {
if (cnt[i] > t[i]) {
ok = false;
break;
}
}

if (ok) {
ans.push(a);
}
}

return ans;
};
34 changes: 34 additions & 0 deletions solution/0900-0999/0916.Word Subsets/Solution.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
function wordSubsets(words1: string[], words2: string[]): string[] {
const cnt: number[] = Array(26).fill(0);
for (const b of words2) {
const t: number[] = Array(26).fill(0);
for (const c of b) {
t[c.charCodeAt(0) - 97]++;
}
for (let i = 0; i < 26; i++) {
cnt[i] = Math.max(cnt[i], t[i]);
}
}

const ans: string[] = [];
for (const a of words1) {
const t: number[] = Array(26).fill(0);
for (const c of a) {
t[c.charCodeAt(0) - 97]++;
}

let ok = true;
for (let i = 0; i < 26; i++) {
if (cnt[i] > t[i]) {
ok = false;
break;
}
}

if (ok) {
ans.push(a);
}
}

return ans;
}