2380. Time Needed to Rearrange a Binary String Medium
1/**
2 * [2380] Time Needed to Rearrange a Binary String
3 *
4 * You are given a binary string s. In one second, all occurrences of "01" are simultaneously replaced with "10". This process repeats until no occurrences of "01" exist.
5 * Return the number of seconds needed to complete this process.
6 *
7 * Example 1:
8 *
9 * Input: s = "0110101"
10 * Output: 4
11 * Explanation:
12 * After one second, s becomes "1011010".
13 * After another second, s becomes "1101100".
14 * After the third second, s becomes "1110100".
15 * After the fourth second, s becomes "1111000".
16 * No occurrence of "01" exists any longer, and the process needed 4 seconds to complete,
17 * so we return 4.
18 *
19 * Example 2:
20 *
21 * Input: s = "11100"
22 * Output: 0
23 * Explanation:
24 * No occurrence of "01" exists in s, and the processes needed 0 seconds to complete,
25 * so we return 0.
26 *
27 *
28 * Constraints:
29 *
30 * 1 <= s.length <= 1000
31 * s[i] is either '0' or '1'.
32 *
33 *
34 * Follow up:
35 * Can you solve this problem in O(n) time complexity?
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/time-needed-to-rearrange-a-binary-string/
41// discuss: https://leetcode.com/problems/time-needed-to-rearrange-a-binary-string/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn seconds_to_remove_occurrences(s: String) -> i32 {
47 0
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_2380() {
59 }
60}
61
Back
© 2025 bowen.ge All Rights Reserved.