JavaScript 116ms


  • 1
    S

    var countBinarySubstrings = function(s) {
    var ary = s.split(''),
    counter = 1,
    temp = ary[0],
    cache = [],
    result = 0
    for (var i = 1, len = ary.length; i < len; i++) {
    if (ary[i] === temp) {
    counter++
    } else {
    cache.push(counter)
    temp = ary[i]
    counter = 1
    }
    }
    cache.push(counter)
    for (var i = 0, len = cache.length; i < len - 1; i++) {
    result += Math.min(cache[i], cache[i + 1])
    }
    return result
    };


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.