0868. Binary Gap
Description
**Input:** n = 22
**Output:** 2
**Explanation:** 22 in binary is "10110".
The first adjacent pair of 1's is "10110" with a distance of 2.
The second adjacent pair of 1's is "10110" with a distance of 1.
The answer is the largest of these two distances, which is 2.
Note that "10110" is not a valid pair since there is a 1 separating the two 1's underlined.**Input:** n = 5
**Output:** 2
**Explanation:** 5 in binary is "101".**Input:** n = 6
**Output:** 1
**Explanation:** 6 in binary is "110".ac
Last updated