less than 1 minute read

Given a non-negative integer n, return the length of the longest consecutive run of 1s in its binary representation.

Constraints

  • 0 ≤ n < 2 ** 31

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

Examples

Example 1

Input

  • n = 156

Output

  • answer = 3

Explanation

156 is10011100 in binary and there’s a run of length 3.

Solution

Leave a comment