Count binary substring

PHOTO EMBED

Thu May 26 2022 19:09:19 GMT+0000 (UTC)

Saved by @joeclaap #javascript #fibonacci #recursion #algorithm

function getSubstringCount(s) {
    // Write your code here
    let [current, prev, result] = [1, 0, 0]
    
    for(let i=1; i<s.length; i++){
        let left = s[i-1]
        let right = s[i]
        if(left == right){
            current++
        } else {
            prev = current
            current = 1
        }
        if(prev >= current){
            result++
        }
    }
    return result
}
content_copyCOPY