Problem statement

https://binarysearch.com/problems/Longest-Consecutive-Run-of-1s-in-Binary/

Solution

Transfrom to string, then use split or groupby.

Complexity

It is O(log n) for time and space.

Code

class Solution:
    def solve(self, n):
        s, ans = bin(n)[2:], 0
        for i, j in groupby(s):
            if i == "1": ans = max(ans, len(list(j)))
        return ans