1525. Number of Good Ways to Split a String Medium

@problem@discussion
#String#Dynamic Programming#Bit Manipulation



1/**
2 * [1525] Number of Good Ways to Split a String
3 *
4 * You are given a string s.
5 * A split is called good if you can split s into two non-empty strings sleft and sright where their concatenation is equal to s (i.e., sleft + sright = s) and the number of distinct letters in sleft and sright is the same.
6 * Return the number of good splits you can make in s.
7 *  
8 * Example 1:
9 * 
10 * Input: s = "aacaba"
11 * Output: 2
12 * Explanation: There are 5 ways to split "aacaba" and 2 of them are good. 
13 * ("a", "acaba") Left string and right string contains 1 and 3 different letters respectively.
14 * ("aa", "caba") Left string and right string contains 1 and 3 different letters respectively.
15 * ("aac", "aba") Left string and right string contains 2 and 2 different letters respectively (good split).
16 * ("aaca", "ba") Left string and right string contains 2 and 2 different letters respectively (good split).
17 * ("aacab", "a") Left string and right string contains 3 and 1 different letters respectively.
18 * 
19 * Example 2:
20 * 
21 * Input: s = "abcd"
22 * Output: 1
23 * Explanation: Split the string as follows ("ab", "cd").
24 * 
25 *  
26 * Constraints:
27 * 
28 * 	1 <= s.length <= 10^5
29 * 	s consists of only lowercase English letters.
30 * 
31 */
32pub struct Solution {}
33
34// problem: https://leetcode.com/problems/number-of-good-ways-to-split-a-string/
35// discuss: https://leetcode.com/problems/number-of-good-ways-to-split-a-string/discuss/?currentPage=1&orderBy=most_votes&query=
36
37// submission codes start here
38
39impl Solution {
40    pub fn num_splits(s: String) -> i32 {
41        0
42    }
43}
44
45// submission codes end
46
47#[cfg(test)]
48mod tests {
49    use super::*;
50
51    #[test]
52    fn test_1525() {
53    }
54}
55


Back
© 2025 bowen.ge All Rights Reserved.