统计是给定字符串前缀的字符串数目
2025-4-20
| 2025-4-20
Words 341Read Time 1 min
type
status
date
slug
summary
tags
category
icon
password

题目:

给你一个字符串数组 words 和一个字符串 s ,其中 words[i]s 只包含 小写英文字母
请你返回 words 中是字符串 s 前缀字符串数目
一个字符串的 前缀 是出现在字符串开头的子字符串。子字符串 是一个字符串中的连续一段字符序列。
来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/SNJvJP 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
示例 1:
示例 2:
提示:
  • 1 <= words.length <= 1000
  • 1 <= words[i].length, s.length <= 10
  • words[i]s 包含小写英文字母。

思路:

  • 遍历,使用startWith方法

代码:

结果:

notion image
image-20220501100125511
维数组的动态和统计各位数字都不同的数字个数-中等
Loading...