Open prabhat010187 opened 2 years ago
the solution is wrong as it did not consider if the len of given string is <=2. correct solution : lower=0 upper=len(aStr)-1 bisec=(lower+upper)//2
if len(aStr)==0: return False elif len(aStr)==1 or len(aStr)==2: if aStr[bisec]==char or aStr[bisec:]==char : return True else: return False elif aStr[bisec]==char: return True elif char>aStr[bisec]: return isIn(char, aStr[bisec+1:]) elif char<aStr[bisec]: return isIn(char, aStr[0:bisec]) else: return False
isIn('n', 'acfhijnpptuvw')
small correction: upper =len(aStr)
the solution is wrong as it did not consider if the len of given string is <=2. correct solution : lower=0 upper=len(aStr)-1 bisec=(lower+upper)//2
isIn('n', 'acfhijnpptuvw')