1573. Number of Ways to Split a String Medium

@problem@discussion
#Math#String



1/**
2 * [1573] Number of Ways to Split a String
3 *
4 * Given a binary string s, you can split s into 3 non-empty strings s1, s2, and s3 where s1 + s2 + s3 = s.
5 * Return the number of ways s can be split such that the number of ones is the same in s1, s2, and s3. Since the answer may be too large, return it modulo 10^9 + 7.
6 *  
7 * Example 1:
8 * 
9 * Input: s = "10101"
10 * Output: 4
11 * Explanation: There are four ways to split s in 3 parts where each part contain the same number of letters '1'.
12 * "1|010|1"
13 * "1|01|01"
14 * "10|10|1"
15 * "10|1|01"
16 * 
17 * Example 2:
18 * 
19 * Input: s = "1001"
20 * Output: 0
21 * 
22 * Example 3:
23 * 
24 * Input: s = "0000"
25 * Output: 3
26 * Explanation: There are three ways to split s in 3 parts.
27 * "0|0|00"
28 * "0|00|0"
29 * "00|0|0"
30 * 
31 *  
32 * Constraints:
33 * 
34 * 	3 <= s.length <= 10^5
35 * 	s[i] is either '0' or '1'.
36 * 
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/number-of-ways-to-split-a-string/
41// discuss: https://leetcode.com/problems/number-of-ways-to-split-a-string/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46    pub fn num_ways(s: String) -> i32 {
47        0
48    }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn test_1573() {
59    }
60}
61


Back
© 2025 bowen.ge All Rights Reserved.