#3677

Count Binary Palindromic Numbers

master · 1885 · lc hard +32 · 33.8% accepted · 79 likes · top 11%

Description

Given a non-negative integer n, count how many integers k in the range [0, n] are binary-palindromic — meaning their binary form (no leading zeros) reads the same forwards and backwards. Note: 0 is represented as "0" and counts as binary-palindromic.

Code

1
2
3