[JavaScript] 1702. Maximum Binary String After Change
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n\n\nExample\n"110000110"\n\nones (111111) on the left\n   at begin of str
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n\n```\nExample\n"110000110"\n\nones (111111) on the left\n   at begin of string\n     are all good, no need to change them\n\nthen some 0s, (1s, 0s, 1s) may come\nin the brackets () above, we can change 10 to 01, so that all 1s will go to right \nfinally we have "some 1s then 0s then 1s"\n\nif we change all 00 to 10, so all 0s will become 1111...0 , only 1 0 at end\nthen we have "some 1s, then only one 0, then 1s", which is our answer\n\nAnswer\n"111111011"\n\nwe dont need to really change, we can count 0s & simulate\nbelow solution does the same\n```\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n\n---\n\n```\nvar maximumBinaryString = function (s) {\n  let n = s.length\n\n  let zeroCount = 0\n  let firstZeroIndex = -1\n  for (let i = 0; i < n; i++) {\n    let ch = s[i]\n    if (ch === \'0\') {\n      zeroCount++\n      if (firstZeroIndex === -1) firstZeroIndex = i\n    }\n  }\n\n  let ans = new Array(n).fill(1)\n  ans[firstZeroIndex + zeroCount - 1] = 0\n  return ans.join("")\n};\n```\n\n---\n
['JavaScript']