1513. Number of Substrings With Only 1s Medium
1/**
2 * [1513] Number of Substrings With Only 1s
3 *
4 * Given a binary string s, return the number of substrings with all characters 1's. Since the answer may be too large, return it modulo 10^9 + 7.
5 *
6 * Example 1:
7 *
8 * Input: s = "0110111"
9 * Output: 9
10 * Explanation: There are 9 substring in total with only 1's characters.
11 * "1" -> 5 times.
12 * "11" -> 3 times.
13 * "111" -> 1 time.
14 * Example 2:
15 *
16 * Input: s = "101"
17 * Output: 2
18 * Explanation: Substring "1" is shown 2 times in s.
19 *
20 * Example 3:
21 *
22 * Input: s = "111111"
23 * Output: 21
24 * Explanation: Each substring contains only 1's characters.
25 *
26 *
27 * Constraints:
28 *
29 * 1 <= s.length <= 10^5
30 * s[i] is either '0' or '1'.
31 *
32 */
33pub struct Solution {}
34
35// problem: https://leetcode.com/problems/number-of-substrings-with-only-1s/
36// discuss: https://leetcode.com/problems/number-of-substrings-with-only-1s/discuss/?currentPage=1&orderBy=most_votes&query=
37
38// submission codes start here
39
40impl Solution {
41 pub fn num_sub(s: String) -> i32 {
42 0
43 }
44}
45
46// submission codes end
47
48#[cfg(test)]
49mod tests {
50 use super::*;
51
52 #[test]
53 fn test_1513() {
54 }
55}
56
Back
© 2025 bowen.ge All Rights Reserved.