2
public long numberOfWays(String s) {3
int zero = 0; // Individual zeroes count4
long zeroOne = 0; // Number of combinations of 01s5
int one = 0; // Individual ones count6
long oneZero = 0; // Number of combinations of 10s7
long tot = 0; // Final answer8
for (char ch : s.toCharArray()) {13
one; // Each of the previously found 1s can pair up with the current 0 to form 1016
zeroOne; // Each of the previously formed 01 can form a triplet with the current 0 to20
if (zero > 0) zeroOne += zero; // Each of the previously found 0s can pair to form 0121
if (oneZero > 0) tot += oneZero; // Each of the previously formed 10 can form 101