Title: #696 - Count Binary Substrings - LeetCode JavaScript Solutions
Open Graph Title: #696 - Count Binary Substrings - LeetCode JavaScript Solutions
X Title: #696 - Count Binary Substrings - LeetCode JavaScript Solutions
Description: Given a binary string s, return the number of non-empty substrings that have the same number of 0's and 1's, and all the 0's ...
Open Graph Description: Given a binary string s, return the number of non-empty substrings that have the same number of 0's and 1's, and all the 0's ...
X Description: Given a binary string s, return the number of non-empty substrings that have the same number of 0's and 1's, and all the 0's ...
Keywords:
Opengraph URL: https://leetcodejavascript.com/solutions/count-binary-substrings
Domain: leetcodejavascript.com
{"@context":"https://schema.org","@type":"Code","url":"https://leetcodejavascript.com/solutions/count-binary-substrings","name":"#696 - Count Binary Substrings - LeetCode JavaScript Solutions","description":"Given a binary string s, return the number of non-empty substrings that have the same number of 0's and 1's, and all the 0's ...","programmingLanguage":"JavaScript","codeRepository":"https://github.com/JoshCrozier/leetcode-javascript","codeSampleType":"JavaScript","text":"/**\n * @param {string} s\n * @return {number}\n */\nvar countBinarySubstrings = function(s) {\n let result = 0;\n\n for (let i = 0, group = [], count = 1, prevCount = 0; i < s.length; i++) {\n if (s[i] === s[i + 1]) {\n count++;\n } else {\n if (prevCount) {\n result += prevCount <= count ? prevCount : count;\n }\n prevCount = count;\n count = 1;\n }\n }\n\n return result;\n};","keywords":"LeetCode 696, #696 - Count Binary Substrings, Easy, 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/count-binary-substrings |
| 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/count-binary-substrings/ |
| View on GitHub | https://github.com/JoshCrozier/leetcode-javascript/blob/master/solutions/0696-count-binary-substrings.js |
| String | https://leetcodejavascript.com/tags/string |
| Two Pointers | https://leetcodejavascript.com/tags/two-pointers |
| Josh Crozier | https://joshcrozier.com |
Viewport: width=device-width, initial-scale=1.0
Robots: index, follow