< Summary

Information
Class: LeetCode.Algorithms.CountSymmetricIntegers.CountSymmetricIntegersIterative
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CountSymmetricIntegers\CountSymmetricIntegersIterative.cs
Line coverage
100%
Covered lines: 23
Uncovered lines: 0
Coverable lines: 23
Total lines: 55
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CountSymmetricIntegers(...)100%88100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CountSymmetricIntegers\CountSymmetricIntegersIterative.cs

#LineLine coverage
 1// --------------------------------------------------------------------------------
 2// Copyright (C) 2025 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.CountSymmetricIntegers;
 13
 14/// <inheritdoc />
 15public class CountSymmetricIntegersIterative : ICountSymmetricIntegers
 16{
 17    /// <summary>
 18    ///     Time complexity - O(N log n)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="low"></param>
 22    /// <param name="high"></param>
 23    /// <returns></returns>
 24    public int CountSymmetricIntegers(int low, int high)
 225    {
 226        var count = 0;
 27
 26628        for (var i = low; i <= high; i++)
 13129        {
 13130            var numString = i.ToString();
 13131            var length = numString.Length;
 32
 13133            if (length % 2 != 0)
 1034            {
 1035                continue;
 36            }
 37
 12138            var n = length / 2;
 24239            int sumLeft = 0, sumRight = 0;
 40
 54641            for (var j = 0; j < n; j++)
 15242            {
 15243                sumLeft += numString[j] - '0';
 15244                sumRight += numString[j + n] - '0';
 15245            }
 46
 12147            if (sumLeft == sumRight)
 1348            {
 1349                count++;
 1350            }
 12151        }
 52
 253        return count;
 254    }
 55}