600. Non-negative Integers without Consecutive Ones Hard

@problem@discussion
#Dynamic Programming



1/**
2 * [600] Non-negative Integers without Consecutive Ones
3 *
4 * Given a positive integer n, return the number of the integers in the range [0, n] whose binary representations do not contain consecutive ones.
5 *  
6 * Example 1:
7 * 
8 * Input: n = 5
9 * Output: 5
10 * Explanation:
11 * Here are the non-negative integers <= 5 with their corresponding binary representations:
12 * 0 : 0
13 * 1 : 1
14 * 2 : 10
15 * 3 : 11
16 * 4 : 100
17 * 5 : 101
18 * Among them, only integer 3 disobeys the rule (two consecutive ones) and the other 5 satisfy the rule. 
19 * 
20 * Example 2:
21 * 
22 * Input: n = 1
23 * Output: 2
24 * 
25 * Example 3:
26 * 
27 * Input: n = 2
28 * Output: 3
29 * 
30 *  
31 * Constraints:
32 * 
33 * 	1 <= n <= 10^9
34 * 
35 */
36pub struct Solution {}
37
38// problem: https://leetcode.com/problems/non-negative-integers-without-consecutive-ones/
39// discuss: https://leetcode.com/problems/non-negative-integers-without-consecutive-ones/discuss/?currentPage=1&orderBy=most_votes&query=
40
41// submission codes start here
42
43impl Solution {
44    pub fn find_integers(n: i32) -> i32 {
45        0
46    }
47}
48
49// submission codes end
50
51#[cfg(test)]
52mod tests {
53    use super::*;
54
55    #[test]
56    fn test_600() {
57    }
58}
59


Back
© 2025 bowen.ge All Rights Reserved.