Title: #761 - Special Binary String - LeetCode JavaScript Solutions
Open Graph Title: #761 - Special Binary String - LeetCode JavaScript Solutions
X Title: #761 - Special Binary String - LeetCode JavaScript Solutions
Description: Special binary strings are binary strings with the following two properties: The number of 0's is equal to the number of 1's. Eve...
Open Graph Description: Special binary strings are binary strings with the following two properties: The number of 0's is equal to the number of 1's. Eve...
X Description: Special binary strings are binary strings with the following two properties: The number of 0's is equal to the number of 1's. Eve...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/special-binary-string
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/special-binary-string","name":"#761 - Special Binary String - LeetCode JavaScript Solutions","description":"Special binary strings are binary strings with the following two properties: The number of 0's is equal to the number of 1's. Eve...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {string} s\n * @return {string}\n */\nfunction makeLargestSpecial(s) {\n if (s.length <= 2) return s;\n\n let count = 0;\n let start = 0;\n const specials = [];\n\n for (let i = 0; i < s.length; i++) {\n count += s[i] === '1' ? 1 : -1;\n\n if (count === 0) {\n specials.push('1' + makeLargestSpecial(s.slice(start + 1, i)) + '0');\n start = i + 1;\n }\n }\n\n return specials.sort().reverse().join('');\n}","keywords":"LeetCode 761, #761 - Special Binary String, Hard, JavaScript solution","learningResourceType":"Code","isAccessibleForFree":true,"educationalLevel":"intermediate","interactivityType":"mixed"}
| author | LeetCodeJavascript.com |
| og:type | article |
| og:image | https://leetcodejavascript.com/og-image.jpg |
| og:site_name | LeetCode JavaScript Solutions |
| twitter:card | summary_large_image |
| twitter:url | https://leetcodejavascript.com/solutions/special-binary-string |
| twitter:image | https://leetcodejavascript.com/og-image.jpg |
| twitter:creator | @joshcrozier |
| theme-color | #1f2937 |
Links:
| LeetCodeJavascript.com | https://leetcodejavascript.com/ |
| Star on GitHub | https://github.com/JoshCrozier/leetcode-javascript |
| Back to all solutions | https://leetcodejavascript.com |
| View on LeetCode | https://leetcode.com/problems/special-binary-string/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0761-special-binary-string.js |
| String | https://leetcodejavascript.com/tags/string |
| Recursion | https://leetcodejavascript.com/tags/recursion |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow