< Summary

Information
Class: LeetCode.Algorithms.SmallestNumberWithAllSetBits.SmallestNumberWithAllSetBitsSwitch
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SmallestNumberWithAllSetBits\SmallestNumberWithAllSetBitsSwitch.cs
Line coverage
53%
Covered lines: 8
Uncovered lines: 7
Coverable lines: 15
Total lines: 39
Line coverage: 53.3%
Branch coverage
38%
Covered branches: 7
Total branches: 18
Branch coverage: 38.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
SmallestNumber(...)38.88%511853.33%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SmallestNumberWithAllSetBits\SmallestNumberWithAllSetBitsSwitch.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2026 Eugene Eremeev (also known as Yevhenii Yeriemeieiv).
 3// All Rights Reserved.
 4// --------------------------------------------------------------------------------
 5// This software is the confidential and proprietary information of Eugene Eremeev
 6// (also known as Yevhenii Yeriemeieiv) ("Confidential Information"). You shall not
 7// disclose such Confidential Information and shall use it only in accordance with
 8// the terms of the license agreement you entered into with Eugene Eremeev (also
 9// known as Yevhenii Yeriemeieiv).
 10// --------------------------------------------------------------------------------
 11
 12namespace LeetCode.Algorithms.SmallestNumberWithAllSetBits;
 13
 14/// <inheritdoc />
 15public sealed class SmallestNumberWithAllSetBitsSwitch : ISmallestNumberWithAllSetBits
 16{
 17    /// <summary>
 18    ///     Time complexity - O(1)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="n"></param>
 22    /// <returns></returns>
 23    public int SmallestNumber(int n)
 324    {
 325        return n switch
 326        {
 027            1 => 1,
 128            <= 3 => 3,
 129            <= 7 => 7,
 130            <= 15 => 15,
 031            <= 31 => 31,
 032            <= 63 => 63,
 033            <= 127 => 127,
 034            <= 255 => 255,
 035            <= 511 => 511,
 036            _ => 1023
 337        };
 338    }
 39}

Methods/Properties

SmallestNumber(System.Int32)