Given a string
s
, return the number of homogenous substrings ofs
. Since the answer may be too large, return it modulo10^9 + 7
.
A string is homogenous if all the characters of the string are the same.
A substring is a contiguous sequence of characters within a string.
Constraints:
1 <= s.length <= 105
s
consists of lowercase letters.
給予一個字串
s
,回傳s
的同質子字串的數量。因為答案可能太大,回傳前請對10^9 + 7
取餘數。
一個字串如果所有的字元都是一樣的,我們稱該字串同質。
子字串是指一個字串中任意連續的字元序列。
限制:
1 <= s.length <= 105
s
只會包含小寫字母。
n
1
個長度為 n
的同質字串2
個長度為 n - 1
的同質字串3
個長度為 n - 2
的同質字串n
個長度為 1
的同質字串1 + 2 + 3 ... + n - 1 + n
個同質字串
(1 + n) * n / 2
aaabb
,我們只須分別算 aaa
和 bb
即可long long
等型別去儲存答案LeetCode
C++