Created
October 2, 2016 16:35
-
-
Save onsmribah/d3db4250a4c30a8f3a83159814c21440 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def max_binary_gaps(n): | |
"""Finds the longest sequence of zeros in binary representation of an integer. | |
:param n: a given integer | |
:rtype: int | |
""" | |
gaps = "{0:b}".format(n).split('1')[1:-1] | |
return len(max(gaps)) if gaps else 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment