Problem
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).
The score after splitting a string is the number of zeros in the left substring plus the number of ones in the right substring.
Examples
Example 1:
|
|
Example 2:
|
|
Example 3:
|
|
Constraints:
2 <= s.length <= 500
- The string
s
consists of characters'0'
and'1'
only.
Solution
Method 1 -
Code
|
|
|
|
Complexity
- ⏰ Time complexity:
O(NNNXXXNNN)
- 🧺 Space complexity:
O(NNNXXX)