classSolution:# @param nums: The integer array# @param target: Target number to find# @return the first position of target in nums, position start from 0 defbinarySearch(self,nums,target):# write your code hereifnums==Noneorlen(nums)==0:return-1front=0end=len(nums)-1result=sys.maxintwhilefront<=end:mid=(front+end)/2ifnums[mid]==target:# we cannot guarantee this "mid" is the first positionifresult>mid:result=mid# we can check the previous posend=mid-1elifnums[mid]>target:end=mid-1else:front=mid+1ifresult==sys.maxint:return-1else:returnresult