fork(3) download
  1. import timeit
  2.  
  3. def solution_MK():
  4. N = 91622823286
  5. cnt = 0
  6. result = 0
  7. found_one = False
  8.  
  9. i = N
  10.  
  11. while i:
  12. if i & 1 == 1:
  13. if (found_one == False):
  14. found_one = True
  15. else:
  16. result = max(result,cnt)
  17. cnt = 0
  18. else:
  19. cnt += 1
  20. i >>= 1
  21.  
  22. return result
  23.  
  24.  
  25. def solution_SJ():
  26. N = 91622823286
  27. binstr = bin(N)[2:].strip("0")
  28. binlst = str(binstr).split("1")
  29. return len(max(binlst))
  30.  
  31.  
  32. print timeit.timeit(solution_MK)
  33. print timeit.timeit(solution_SJ)
  34.  
Time limit exceeded #stdin #stdout 5s 9120KB
stdin
Standard input is empty
stdout
Standard output is empty