Skip to content

Commit 36baf86

Browse files
committed
if (w.length > s.length) continue;
1 parent 0d9ad4e commit 36baf86

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

number-of-matching-subsequences/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function numMatchingSubseq(s: string, words: string[]): number {
77
.map(() => new Set<[string, number]>());
88

99
for (const [w, count] of cnt) {
10+
if (w.length > s.length) continue;
1011
arr[w.charCodeAt(0) - "a".charCodeAt(0)].add([w, count]);
1112
}
1213
let res = 0;

number-of-matching-subsequences/numMatchingSubseq.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export default function numMatchingSubseq(s: string, words: string[]): number {
44
const cnt = counter(words);
55
let res = 0;
66
for (const [w, count] of cnt) {
7+
if (w.length > s.length) continue;
78
if (isSubsequence(w, s)) res += count;
89
}
910
return res;

0 commit comments

Comments
 (0)