Can someone explain why this works?

https://www.geeksforgeeks.org/substring-equal-number-0-1-2/