Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace index_of_last_zero
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- string input = Console.ReadLine();
- int indexOfLastZero = GetIndexOfLastZero(input);
- Console.WriteLine(indexOfLastZero);
- }
- private static int GetIndexOfLastZero(string input)
- {
- int l = 0, r = input.Length - 1;
- int retrunValue = -1;
- while (l <= r)
- {
- int m = (l + r) / 2;
- if (input[m] == '0' && m < input.Length - 1 && input[m + 1] == '1')
- {
- return m;
- }
- if (input[m] == '0')
- {
- l = m + 1;
- retrunValue = input.Length - 1;
- }
- else
- {
- r = m - 1;
- }
- }
- return retrunValue;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment