Skip to content

Latest commit

 

History

History
20 lines (17 loc) · 436 Bytes

Question_3370.md

File metadata and controls

20 lines (17 loc) · 436 Bytes

LeetCode Records - Question 3370 Smallest Number With All Set Bits

Attempt 1: Use a while loop to generate the smallest number

class Solution {
    public int smallestNumber(int n) {
        int ans = 0;
        while (n > 0) {
            n >>>= 1;
            ans = (ans << 1) + 1;
        }

        return ans;
    }
}
  • Runtime: 0 ms (Beats: 100.00%)
  • Memory: 40.45 MB (Beats: 100.00%)