Created
September 28, 2015 21:25
-
-
Save fschr/98f011d32f176058e32e 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
class Wrapper: | |
memo = dict() | |
@staticmethod | |
def countOnes(n): | |
if n == 0: | |
return 0 | |
if n == 1: | |
Wrapper.memo[1] = 1 | |
return 1 | |
val = 1 + Wrapper.countOnes(n - 2**(n.bit_length() - 1)) | |
Wrapper.memo[n] = val | |
return val |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment