Skip to main content

1680 - Concatenation of Consecutive Binary Numbers

Details

KeyValue
Linkhttps://leetcode.com/problems/concatenation-of-consecutive-binary-numbers/
LanguagePython 3
Runtime1695 ms, faster than 75.97% of Python3 online submissions for Concatenation of Consecutive Binary Numbers
Memory Usage15.9 MB, less than 34.11% of Python3 online submissions for Concatenation of Consecutive Binary Numbers
Datastructuresint, bin, str
AlgorithmsBinary Conversion + String Concatenation
ComplexityTime: O(N) Memory: O(N)

Procedure

  1. ...

Code

class Solution:
def concatenatedBinary(self, n: int) -> int:
result = ""

for i in range(1,n+1):
result += format(i,"b")

return int(result,2) % (10**9 + 7)