给你一个字符串 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
s
和 c
均由小写英文字母组成。'c'
in string s
, let’s call it m
.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.m * (m + 1) / 2
.