---
# System prepended metadata

title: 0696. Count Binary Substrings
tags: [Leetcode, Medium, TikTok]

---

# 0696. Count Binary Substrings
###### tags: `Leetcode` `Medium` `TikTok`
Link: https://leetcode.com/problems/count-binary-substrings/
## Code
```java=
class Solution {
    public int countBinarySubstrings(String s) {
        int ans = 0;
        int prev = 0;
        int curr = 1;
        char prevChar = s.charAt(0);
        char[] charArray = s.toCharArray();
        
        for(int i = 1;i < s.length();i++){
            if(prevChar == s.charAt(i)){
                curr++;
            }
            else{
                ans+=Math.min(prev, curr);
                prev = curr;
                curr = 1;
                prevChar = s.charAt(i);
            }
        }
        ans+=Math.min(prev, curr);
        return ans;
    }
}
```