Runtime error in a possibly correct solution

My solution
is throwing RUNTIME error on some test cases but I believe the solution is alright.

My algorithm: I just counted the number of ‘01’ in the string and decremented it by 1 if the first character of the string is ‘0’ and increment it by 1 if the last character of the string is ‘0’.