O(n) | C++
\tclass Solution {\n\tpublic:\n\t\tstring maximumBinaryString(string binary) {\n\t\t\tif(binary.size()==0)\n\t\t\t\treturn "";\n\t\t\tstring ans="";\n\t\t\tint 
\tclass Solution {\n\tpublic:\n\t\tstring maximumBinaryString(string binary) {\n\t\t\tif(binary.size()==0)\n\t\t\t\treturn "";\n\t\t\tstring ans="";\n\t\t\tint lastzero=binary[0]==\'0\'?0:-1;\n\t\t\tfor(int i=1;i<binary.length();i++){\n\t\t\t\tif( binary[i]==\'0\' && binary[i-1]==\'0\'){\n\t\t\t\t\tbinary[i-1]=\'1\';\n\t\t\t\t\tlastzero=i;\n\t\t\t\t}else if(binary[i]==\'0\' && lastzero==-1){\n\t\t\t\t\tlastzero=i;\n\t\t\t\t}else if(binary[i]==\'0\' && lastzero!=-1){\n\t\t\t\t\tbinary[lastzero]=\'1\';\n\t\t\t\t\tbinary[lastzero+1]=\'0\';\n\t\t\t\t\tlastzero++;\n\t\t\t\t\tbinary[i]=\'1\';\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn binary;\n\n\t\t}\n\t};
[]