【leetcode】696. 计数二进制子串
#define min(a,b) (a<b)?(a) :(b) int countBinarySubstrings(char * s){ int i, j, cnt = 0, len = strlen(s), sum=0, preVal=0, ret; for (i = 0; i < len; i++){ cnt++; if (i == len-1 || s[i] != s[i + 1]){ sum += min(cnt, preVal); preVal = cnt; cnt = 0; } } return sum; }