3677. Count Binary Palindromic Numbers Hard
1/**
2 * [3677] Count Binary Palindromic Numbers
3 *
4 * You are given a non-negative integer n.
5 * A non-negative integer is called binary-palindromic if its binary representation (written without leading zeros) reads the same forward and backward.
6 * Return the number of integers <font face="monospace">k</font> such that 0 <= k <= n and the binary representation of <font face="monospace">k</font> is a palindrome.
7 * Note: The number 0 is considered binary-palindromic, and its representation is "0".
8 *
9 * <strong class="example">Example 1:
10 * <div class="example-block">
11 * Input: <span class="example-io">n = 9</span>
12 * Output: <span class="example-io">6</span>
13 * Explanation:
14 * The integers k in the range [0, 9] whose binary representations are palindromes are:
15 *
16 * 0 → "0"
17 * 1 → "1"
18 * 3 → "11"
19 * 5 → "101"
20 * 7 → "111"
21 * 9 → "1001"
22 *
23 * All other values in [0, 9] have non-palindromic binary forms. Therefore, the count is 6.
24 * </div>
25 * <strong class="example">Example 2:
26 * <div class="example-block">
27 * Input: <span class="example-io">n = 0</span>
28 * Output: <span class="example-io">1</span>
29 * Explanation:
30 * Since "0" is a palindrome, the count is 1.
31 * </div>
32 *
33 * Constraints:
34 *
35 * 0 <= n <= 10^15
36 *
37 */
38pub struct Solution {}
39
40// problem: https://leetcode.com/problems/count-binary-palindromic-numbers/
41// discuss: https://leetcode.com/problems/count-binary-palindromic-numbers/discuss/?currentPage=1&orderBy=most_votes&query=
42
43// submission codes start here
44
45impl Solution {
46 pub fn count_binary_palindromes(n: i64) -> i32 {
47 0
48 }
49}
50
51// submission codes end
52
53#[cfg(test)]
54mod tests {
55 use super::*;
56
57 #[test]
58 fn test_3677() {
59 }
60}
61Back
© 2026 bowen.ge All Rights Reserved.