Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int countBinarySubstrings(string s) {
- int n = s.size();
- int i = 0, j = 0;
- int cnt = 0, ans = 0;
- while (i < n and j < n) {
- if (s[i] == s[j]) {
- cnt++;
- j++;
- }
- else {
- cnt--;
- j++;
- }
- if (cnt == 0) {
- ans++;
- i++;
- j = i;
- }
- if (j == n) {
- cnt = 0;
- i++;
- j = i;
- }
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement