@dis_rain I'm glad you asked. It's made me think more deeply about this problem.
So here's my understanding of the problem because @compton_scatter left his out. If somebody reading this sees a mistake in my understanding, please let me know.
currRunLength - this keeps track of the current count of contiguous 1's or 0's that you've currently seen
prevRunLength - this keeps track of the previous count of contiguous 1's or 0's that you've currently seen
The first if/else block manipulates these variables
The last if statement is for checking how many valid substrings you have seen so far in the iteration. For any value of prevRunLength > 1, we can only have prevRunLength valid substrings up until prevRunLength is manipulated (this happens when we see mismatching digits)