1422. Maximum Score After Splitting a String Easy

@problem@discussion
#String



1/**
2 * [1422] Maximum Score After Splitting a String
3 *
4 * Given a string s of zeros and ones, return the maximum score after splitting the string into two non-empty substrings (i.e. left substring and right substring).
5 * The score after splitting a string is the number of zeros in the left substring plus the number of ones in the right substring.
6 *  
7 * Example 1:
8 * 
9 * Input: s = "011101"
10 * Output: 5 
11 * Explanation: 
12 * All possible ways of splitting s into two non-empty substrings are:
13 * left = "0" and right = "11101", score = 1 + 4 = 5 
14 * left = "01" and right = "1101", score = 1 + 3 = 4 
15 * left = "011" and right = "101", score = 1 + 2 = 3 
16 * left = "0111" and right = "01", score = 1 + 1 = 2 
17 * left = "01110" and right = "1", score = 2 + 1 = 3
18 * 
19 * Example 2:
20 * 
21 * Input: s = "00111"
22 * Output: 5
23 * Explanation: When left = "00" and right = "111", we get the maximum score = 2 + 3 = 5
24 * 
25 * Example 3:
26 * 
27 * Input: s = "1111"
28 * Output: 3
29 * 
30 *  
31 * Constraints:
32 * 
33 * 	2 <= s.length <= 500
34 * 	The string s consists of characters '0' and '1' only.
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/maximum-score-after-splitting-a-string/
40// discuss: https://leetcode.com/problems/maximum-score-after-splitting-a-string/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn max_score(s: String) -> i32 {
46        0
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_1422() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.