Created
July 21, 2018 11:27
-
-
Save luojiyin1987/62623e1aefaa2304545cc7822759ede9 to your computer and use it in GitHub Desktop.
Binary Gap
This file contains hidden or 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 binaryGap(self, N): | |
| """ | |
| :type N: int | |
| :rtype: int | |
| """ | |
| result = 0 | |
| last = None | |
| for i in range(32): | |
| if (N >> i) & 1: | |
| if last is not None: | |
| result = max(result, i-last) | |
| last = i | |
| return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment