Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def binarysearch(A,start,end,x):
- if (start > end):
- return -1
- mid=(start+end)//2
- if (A[mid]==x):
- return mid
- else:
- if(x< A[mid]):
- return binarysearch(A,start,mid-1,x)
- else:
- return binarysearch(A,mid+1,end,x)
- def findCount(A,x):
- n=len(A)
- start=0
- end=n-1
- index= binarysearch(A,start,end,x)
- if (index==-1):
- return 0
- count=1
- left=index-1
- return index
- A=[5,5,6,6,6,6,7,8,8,8,9,9,9]
- x=9
- print(findCount(A,x))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement