1702. Maximum Binary String After Change Medium
1/**
2 * [1702] Maximum Binary String After Change
3 *
4 * You are given a binary string binary consisting of only 0's or 1's. You can apply each of the following operations any number of times:
5 *
6 * Operation 1: If the number contains the substring "00", you can replace it with "10".
7 *
8 * For example, "<u>00</u>010" -> "<u>10</u>010"
9 *
10 *
11 * Operation 2: If the number contains the substring "10", you can replace it with "01".
12 *
13 * For example, "000<u>10</u>" -> "000<u>01</u>"
14 *
15 *
16 *
17 * Return the maximum binary string you can obtain after any number of operations. Binary string x is greater than binary string y if x's decimal representation is greater than y's decimal representation.
18 *
19 * Example 1:
20 *
21 * Input: binary = "000110"
22 * Output: "111011"
23 * Explanation: A valid transformation sequence can be:
24 * "0001<u>10</u>" -> "0001<u>01</u>"
25 * "<u>00</u>0101" -> "<u>10</u>0101"
26 * "1<u>00</u>101" -> "1<u>10</u>101"
27 * "110<u>10</u>1" -> "110<u>01</u>1"
28 * "11<u>00</u>11" -> "11<u>10</u>11"
29 *
30 * Example 2:
31 *
32 * Input: binary = "01"
33 * Output: "01"
34 * Explanation: "01" cannot be transformed any further.
35 *
36 *
37 * Constraints:
38 *
39 * 1 <= binary.length <= 10^5
40 * binary consist of '0' and '1'.
41 *
42 */
43pub struct Solution {}
44
45// problem: https://leetcode.com/problems/maximum-binary-string-after-change/
46// discuss: https://leetcode.com/problems/maximum-binary-string-after-change/discuss/?currentPage=1&orderBy=most_votes&query=
47
48// submission codes start here
49
50impl Solution {
51 pub fn maximum_binary_string(binary: String) -> String {
52 String::new()
53 }
54}
55
56// submission codes end
57
58#[cfg(test)]
59mod tests {
60 use super::*;
61
62 #[test]
63 fn test_1702() {
64 }
65}
66
Back
© 2025 bowen.ge All Rights Reserved.