#NEWLINE# def binarySearch( self , nums , target ) : #NEWLINE# #INDENT# '\n        basics\n\n        :param nums: The integer array\n        :param target: Target number to find\n        :return the first position of target in nums, position start from 0\n        ' #NEWLINE# l = 0 #NEWLINE# h = len ( nums ) #NEWLINE# while ( l < h ) : #NEWLINE# #INDENT# mid = ( ( l + h ) / 2 ) #NEWLINE# if ( nums [ mid ] == target ) : #NEWLINE# #INDENT# while ( ( mid >= 0 ) and ( nums [ ( mid - 1 ) ] == nums [ mid ] ) ) : #NEWLINE# #INDENT# mid -= 1 #NEWLINE# #UNINDENT# return mid #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( nums [ mid ] < target ) : #NEWLINE# #INDENT# l = ( mid + 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# h = target #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return ( - 1 )