blob: 804d9d59d6a189f37dac47faa8c61a050a38d345 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
def first(arr,x,n):
low = 0
high = n - 1
res = -1
while (low <= high):
mid = (low + high) // 2
if arr[mid] > x:
high = mid - 1
elif arr[mid] < x:
low = mid + 1
else:
res = mid
high = mid - 1
return res
|