Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- int test(int* arr,int size);
- void main()
- {
- // int arr[] = {-3,-2,-1,0,1,2,3,3,4,5,6,7,8,9};
- // int arr[] = {0,0,1,2,3,4,5,6,7,8,9,10,11,12};
- int arr[] ={-3,-2,-1,0,1,2,3,4,5,6,7,8,8};
- printf("%d \n",test(arr, 14));
- }
- int test(int* arr,int size)
- {
- int mid,low =0,high = size-1;
- while (low <= high)
- {
- mid = (high + low) / 2;
- if (arr[mid] == arr[mid +1] || arr[mid] == arr[mid -1] )
- {
- return arr[mid];
- }
- if (arr[mid] - arr[0] == mid)
- low = mid +1;
- else
- high = mid -1;
- }
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement