FPEvalRepoPublic/LeetCodeMetaData
0399
1{2 "id": 2464,3 "name": "time-needed-to-rearrange-a-binary-string",4 "difficulty": "Medium",5 "link": "https://leetcode.com/problems/time-needed-to-rearrange-a-binary-string/",6 "date": "2022-08-06",7 "task_description": "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. Return_ the number of seconds needed to complete this process._ **Example 1:** ``` **Input:** s = \"0110101\" **Output:** 4 **Explanation:** After one second, s becomes \"1011010\". After another second, s becomes \"1101100\". After the third second, s becomes \"1110100\". After the fourth second, s becomes \"1111000\". No occurrence of \"01\" exists any longer, and the process needed 4 seconds to complete, so we return 4. ``` **Example 2:** ``` **Input:** s = \"11100\" **Output:** 0 **Explanation:** No occurrence of \"01\" exists in s, and the processes needed 0 seconds to complete, so we return 0. ``` **Constraints:** `1 <= s.length <= 1000` `s[i]` is either `'0'` or `'1'`. **Follow up:** Can you solve this problem in O(n) time complexity?",8 "test_case": [9 {10 "label": "Example 1",11 "input": "s = \"0110101\"",12 "output": "4 "13 },14 {15 "label": "Example 2",16 "input": "s = \"11100\"",17 "output": "0 "18 }19 ],20 "constraints": [21 "1 <= s.length <= 1000",22 "s[i] is either '0' or '1'."23 ],24 "python_template": "class Solution(object):\n def secondsToRemoveOccurrences(self, s):\n \"\"\"\n :type s: str\n :rtype: int\n \"\"\"\n ",25 "java_template": "class Solution {\n public int secondsToRemoveOccurrences(String s) {\n \n }\n}",26 "metadata": {27 "func_name": "secondsToRemoveOccurrences"28 }29}