< Summary

Information
Class: LeetCode.Algorithms.SelfDividingNumbers.SelfDividingNumbersMath
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SelfDividingNumbers\SelfDividingNumbersMath.cs
Line coverage
100%
Covered lines: 26
Uncovered lines: 0
Coverable lines: 26
Total lines: 62
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
SelfDividingNumbers(...)100%44100%
IsSelfDividing(...)100%66100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SelfDividingNumbers\SelfDividingNumbersMath.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.SelfDividingNumbers;
 13
 14/// <inheritdoc />
 15public sealed class SelfDividingNumbersMath : ISelfDividingNumbers
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n * d), where n is range size and d is digit count
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="left"></param>
 22    /// <param name="right"></param>
 23    /// <returns></returns>
 24    public IList<int> SelfDividingNumbers(int left, int right)
 225    {
 226        var result = new List<int>();
 27
 12628        for (var number = left; number <= right; number++)
 6129        {
 6130            if (IsSelfDividing(number))
 1731            {
 1732                result.Add(number);
 1733            }
 6134        }
 35
 236        return result;
 237    }
 38
 39    private static bool IsSelfDividing(int number)
 6140    {
 6141        var temp = number;
 42
 10143        while (temp > 0)
 8444        {
 8445            var digit = temp % 10;
 46
 8447            if (digit == 0)
 648            {
 649                return false;
 50            }
 51
 7852            if (number % digit != 0)
 3853            {
 3854                return false;
 55            }
 56
 4057            temp /= 10;
 4058        }
 59
 1760        return true;
 6161    }
 62}