1759. Count Number of Homogenous Substrings Medium
1/**
2 * [1759] Count Number of Homogenous Substrings
3 *
4 * Given a string s, return the number of homogenous substrings of s. Since the answer may be too large, return it modulo 10^9 + 7.
5 *
6 * A string is homogenous if all the characters of the string are the same.
7 *
8 * A substring is a contiguous sequence of characters within a string.
9 *
10 *
11 * Example 1:
12 *
13 *
14 * Input: s = "abbcccaa"
15 * Output: 13
16 * Explanation: The homogenous substrings are listed as below:
17 * "a" appears 3 times.
18 * "aa" appears 1 time.
19 * "b" appears 2 times.
20 * "bb" appears 1 time.
21 * "c" appears 3 times.
22 * "cc" appears 2 times.
23 * "ccc" appears 1 time.
24 * 3 + 1 + 2 + 1 + 3 + 2 + 1 = 13.
25 *
26 * Example 2:
27 *
28 *
29 * Input: s = "xy"
30 * Output: 2
31 * Explanation: The homogenous substrings are "x" and "y".
32 *
33 * Example 3:
34 *
35 *
36 * Input: s = "zzzzz"
37 * Output: 15
38 *
39 *
40 *
41 * Constraints:
42 *
43 *
44 * 1 <= s.length <= 10^5
45 * s consists of lowercase letters.
46 *
47 */
48pub struct Solution {}
49
50// problem: https://leetcode.com/problems/count-number-of-homogenous-substrings/
51// discuss: https://leetcode.com/problems/count-number-of-homogenous-substrings/discuss/?currentPage=1&orderBy=most_votes&query=
52
53// submission codes start here
54
55impl Solution {
56 pub fn count_homogenous(s: String) -> i32 {
57 0
58 }
59}
60
61// submission codes end
62
63#[cfg(test)]
64mod tests {
65 use super::*;
66
67 #[test]
68 fn test_1759() {
69 }
70}
71
Back
© 2025 bowen.ge All Rights Reserved.