调试中...
调试中...
题目描述
题目描述
题解
题解
提交记录
提交记录
代码
代码
测试用例
测试用例
测试结果
测试结果
中等
相关标签
相关企业
提示

给你一个字符串 s 和一个字符 c 。返回在字符串 s 中并且以 c 字符开头和结尾的的总数。

 

示例 1:

输入:s = "abada", c = "a"

输出:6

解释:"a" 开头和结尾的子字符串有: "abada""abada""abada""abada""abada""abada"

示例 2:

输入:s = "zzz", c = "z"

输出:6

解释:字符串 s 中总共有 6 个子字符串,并且它们都以 "z" 开头和结尾。

 

提示:

  • 1 <= s.length <= 105
  • sc 均由小写英文字母组成。
通过次数
7.9K
提交次数
14.8K
通过率
53.1%


相关企业

提示 1
Count the number of characters 'c' in string s, let’s call it m.

提示 2
We can select 2 numbers i and j such that i <= j are the start and end indices of substring. Note that i and j can be the same.

提示 3
The answer is m * (m + 1) / 2.

评论 (0)

贡献者
© 2025 领扣网络(上海)有限公司
0 人在线
行 1,列 1
运行和提交代码需要登录
s =
"abada"
c =
"a"
Source