Any 1/0 string with at least one trailing 0 can be seeing as repeating of a pattern: a ones followed by 1 zero. We denote such a pattern by p(a). Eg:

p(1) =def= 10
p(3) =def= 1110
p(5) =def= 111110
p(0) =def= 0

pay attention to the last one. Also note that, each occurrence of 0 signals the end of such a pattern.

And such a string 0011011100 can be seen as p(0) + p(0) + p(2) + p(3) + p(0). Reminder, count a pattern at its trailing 0.

In OP's solution, the two variables zeroLeft and zeroRight serve these purposes: for each iteration, or index i

zeroLeft: the length of pattern that ends no later than i.
zeroRight: the length of the run of 1 if i is in one. 0 otherwise.

Here is a trace for your convenience :

0 0 1 1 0 1 1 1 0 0 1 1 1 1 0 //entry
0 1 1 1 1 3 3 3 3 4 1 1 1 1 1 5 //zeroLeft
0 0 0 1 2 0 1 2 3 0 0 1 2 3 4 0 //zeroRight

So, at each i that is 1, we consider zeroLeft + zeroRight because for an example like 110111, we are considering len(p(2)) + len(run(3)) (run(3) as 3 consecutive 1s).

The code's logic:

For each index i:
if nums[i] is 0: calculate the length of the pattern that ends at nums[i] , and put it into zeroLeft. Reset zeroRight because we are no longer in a run;
if nums[i] is 1: increment zeroRight which records run length, and try to update max with (zeroLeft + zeroRight);

Of course, OP wrote his code in another way, but I think that is the logic here. I solved this problem with a similar approach (considering the separating zeroes), but OP's code is way more elegant than mine.

Again, this is only my way of interpreting this program, and it's highly unlikely this is the thinking process of OP himself. The concept of a pattern is coined not necessarily. I do hope this will aid in the process of you finding your own way of interpretation.