Skip to content

1967. 作为子字符串出现在单词中的字符串数目 ​

  • 题号:1967
  • 来源:LeetCode
  • 难度:简单
  • 标签:字符串
  • 语言:TypeScript
  • 解法:1 个
  • 作者:lmliheng
  • 最近更新:2026-09-27

TypeScript · O(m*n) 时间 · O(1) 空间 · 更新于 2026-09-27

用 indexOf 逐个判断 pattern 是否出现

typescript
/**
 * @difficulty easy
 * @tags 字符串
 * @time O(m*n)
 * @space O(1)
 * @note 用 indexOf 逐个判断 pattern 是否出现
 * @1967. 作为子字符串出现在单词中的字符串数目
 */

let patterns: string[] = ["a", "abc", "bc", "d"]
let word: string = "abc"
let res: number = 0
for (let i: number = 0; i < patterns.length; i++) {
    if (word.indexOf(patterns[i])!==-1) {
        res++
    }
}

console.log(res)

export {};

源码:ts/leetcode/1967. 作为子字符串出现在单词中的字符串数目.ts


在 GitHub 上查看题目所在目录:lmliheng/algorithm