3370. Smallest Number With All Set Bits Easy
1/**
2 * [3370] Smallest Number With All Set Bits
3 *
4 * You are given a positive number n.
5 * Return the smallest number x greater than or equal to n, such that the binary representation of x contains only <span data-keyword="set-bit">set bits</span>
6 *
7 * <strong class="example">Example 1:
8 * <div class="example-block">
9 * Input: <span class="example-io">n = 5</span>
10 * Output: <span class="example-io">7</span>
11 * Explanation:
12 * The binary representation of 7 is "111".
13 * </div>
14 * <strong class="example">Example 2:
15 * <div class="example-block">
16 * Input: <span class="example-io">n = 10</span>
17 * Output: <span class="example-io">15</span>
18 * Explanation:
19 * The binary representation of 15 is "1111".
20 * </div>
21 * <strong class="example">Example 3:
22 * <div class="example-block">
23 * Input: <span class="example-io">n = 3</span>
24 * Output: <span class="example-io">3</span>
25 * Explanation:
26 * The binary representation of 3 is "11".
27 * </div>
28 *
29 * Constraints:
30 *
31 * 1 <= n <= 1000
32 *
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/smallest-number-with-all-set-bits/
37// discuss: https://leetcode.com/problems/smallest-number-with-all-set-bits/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42 pub fn smallest_number(n: i32) -> i32 {
43 0
44 }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51 use super::*;
52
53 #[test]
54 fn test_3370() {
55 }
56}
57
Back
© 2025 bowen.ge All Rights Reserved.