3228. Maximum Number of Operations to Move Ones to the End Medium
1/**
2 * [3228] Maximum Number of Operations to Move Ones to the End
3 *
4 * You are given a <span data-keyword="binary-string">binary string</span> s.
5 * You can perform the following operation on the string any number of times:
6 *
7 * Choose any index i from the string where i + 1 < s.length such that s[i] == '1' and s[i + 1] == '0'.
8 * Move the character s[i] to the right until it reaches the end of the string or another '1'. For example, for s = "010010", if we choose i = 1, the resulting string will be s = "0<u>001</u>10".
9 *
10 * Return the maximum number of operations that you can perform.
11 *
12 * <strong class="example">Example 1:
13 * <div class="example-block">
14 * Input: <span class="example-io">s = "1001101"</span>
15 * Output: <span class="example-io">4</span>
16 * Explanation:
17 * We can perform the following operations:
18 *
19 * Choose index i = 0. The resulting string is s = "<u>001</u>1101".
20 * Choose index i = 4. The resulting string is s = "0011<u>01</u>1".
21 * Choose index i = 3. The resulting string is s = "001<u>01</u>11".
22 * Choose index i = 2. The resulting string is s = "00<u>01</u>111".
23 * </div>
24 * <strong class="example">Example 2:
25 * <div class="example-block">
26 * Input: <span class="example-io">s = "00111"</span>
27 * Output: <span class="example-io">0</span>
28 * </div>
29 *
30 * Constraints:
31 *
32 * 1 <= s.length <= 10^5
33 * s[i] is either '0' or '1'.
34 *
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/maximum-number-of-operations-to-move-ones-to-the-end/
39// discuss: https://leetcode.com/problems/maximum-number-of-operations-to-move-ones-to-the-end/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44 pub fn max_operations(s: String) -> i32 {
45 0
46 }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn test_3228() {
57 }
58}
59
Back
© 2025 bowen.ge All Rights Reserved.