@@ -214,6 +214,94 @@ func wordSubsets(words1 []string, words2 []string) (ans []string) {
214214}
215215```
216216
217+ #### TypeScript
218+
219+ ``` ts
220+ function wordSubsets(words1 : string [], words2 : string []): string [] {
221+ const cnt: number [] = Array (26 ).fill (0 );
222+ for (const b of words2 ) {
223+ const t: number [] = Array (26 ).fill (0 );
224+ for (const c of b ) {
225+ t [c .charCodeAt (0 ) - 97 ]++ ;
226+ }
227+ for (let i = 0 ; i < 26 ; i ++ ) {
228+ cnt [i ] = Math .max (cnt [i ], t [i ]);
229+ }
230+ }
231+
232+ const ans: string [] = [];
233+ for (const a of words1 ) {
234+ const t: number [] = Array (26 ).fill (0 );
235+ for (const c of a ) {
236+ t [c .charCodeAt (0 ) - 97 ]++ ;
237+ }
238+
239+ let ok = true ;
240+ for (let i = 0 ; i < 26 ; i ++ ) {
241+ if (cnt [i ] > t [i ]) {
242+ ok = false ;
243+ break ;
244+ }
245+ }
246+
247+ if (ok ) {
248+ ans .push (a );
249+ }
250+ }
251+
252+ return ans ;
253+ }
254+ ```
255+
256+ #### JavaScript
257+
258+ ``` js
259+ /**
260+ * @param {string[]} words1
261+ * @param {string[]} words2
262+ * @return {string[]}
263+ */
264+ var wordSubsets = function (words1 , words2 ) {
265+ const cnt = Array (26 ).fill (0 );
266+
267+ for (const b of words2) {
268+ const t = Array (26 ).fill (0 );
269+
270+ for (const c of b) {
271+ t[c .charCodeAt (0 ) - 97 ]++ ;
272+ }
273+
274+ for (let i = 0 ; i < 26 ; i++ ) {
275+ cnt[i] = Math .max (cnt[i], t[i]);
276+ }
277+ }
278+
279+ const ans = [];
280+
281+ for (const a of words1) {
282+ const t = Array (26 ).fill (0 );
283+
284+ for (const c of a) {
285+ t[c .charCodeAt (0 ) - 97 ]++ ;
286+ }
287+
288+ let ok = true ;
289+ for (let i = 0 ; i < 26 ; i++ ) {
290+ if (cnt[i] > t[i]) {
291+ ok = false ;
292+ break ;
293+ }
294+ }
295+
296+ if (ok) {
297+ ans .push (a);
298+ }
299+ }
300+
301+ return ans;
302+ };
303+ ```
304+
217305<!-- tabs: end -->
218306
219307<!-- solution: end -->
0 commit comments