My code:
s = '101000101'
for i in range(len(s)-1): # check till second last element
if s[i] == '0' and s[i+1] == '1':
print("Exists")
break
In built function:
s = '101000101'
if '01' in s:
print("Exists")
I have performed both code on hundreds of large strings. And outcome has huge difference.
My code time: 1.26
In built code time: 0.02
At my knowledge, I think I have used simplest and atmost required algorithm. I don't think so there exists better way to search. Then why I am seeing this much difference in outcome?