Java greedy solution | Time complexity O(n)
\nclass Solution {\n    public String maximumBinaryString(String binary) {\n        int n = binary.length();\n        StringBuffer ans = new StringBuffer("");\n
```\nclass Solution {\n    public String maximumBinaryString(String binary) {\n        int n = binary.length();\n        StringBuffer ans = new StringBuffer("");\n        StringBuffer buffer = new StringBuffer("");\n        int onesAfter1stZero = 0;\n        boolean found1stZero = false;\n        for(int i=0;i<n;i++){\n            if(found1stZero){\n                if(binary.charAt(i)==\'0\')\n                    ans.append(\'1\');\n                else\n                    buffer.append(\'1\');\n            }\n            else{\n                if(binary.charAt(i)==\'0\'){\n                    found1stZero = true;\n                    buffer.append(\'0\');\n                }\n                else\n                    ans.append(\'1\');\n            }\n        }\n        \n        ans.append(buffer);\n        return ans.toString();\n    }\n}\n```
['String', 'Greedy', 'Simulation', 'Java']