Guest User

Untitled

a guest
Dec 13th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. def solution(N):
  2. max_gap=0
  3. current_gap=0
  4.  
  5. while N>0 and N%2==0:
  6. #print([N,current_gap,max_gap,"{0:b}".format(N)])
  7. N//=2
  8.  
  9. while N>0:
  10. if N%2==0:
  11. current_gap+=1
  12. else:
  13. if current_gap!=0:
  14. max_gap=max(current_gap,max_gap)
  15. current_gap=0
  16.  
  17. #print([N,current_gap,max_gap,"{0:b}".format(N)])
  18. N//=2
  19.  
  20. return max_gap
  21.  
  22. solution(1042)
Add Comment
Please, Sign In to add comment