< Summary

Information
Class: LeetCode.Algorithms.PalindromeNumber.PalindromeNumberByConvertingToString
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\PalindromeNumber\PalindromeNumberByConvertingToString.cs
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 57
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
IsPalindrome(...)100%1010100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\PalindromeNumber\PalindromeNumberByConvertingToString.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.PalindromeNumber;
 13
 14/// <inheritdoc />
 15public class PalindromeNumberByConvertingToString : IPalindromeNumber
 16{
 17    /// <summary>
 18    ///     Time complexity - O(d), where d is the number of digits in the integer x
 19    ///     Space complexity - O(d), where d is the number of digits in the integer x
 20    /// </summary>
 21    /// <param name="x"></param>
 22    /// <returns></returns>
 23    public bool IsPalindrome(int x)
 1724    {
 1725        switch (x)
 26        {
 27            case < 0:
 228                return false;
 29            case < 10:
 330                return true;
 31        }
 32
 1233        if (x % 10 == 0)
 234        {
 235            return false;
 36        }
 37
 1038        var xString = x.ToString();
 1039        var i = 0;
 1040        var j = xString.Length - 1;
 41
 2942        while (i < j)
 2043        {
 2044            if (xString[i].Equals(xString[j]))
 1945            {
 1946                i++;
 1947                j--;
 1948            }
 49            else
 150            {
 151                return false;
 52            }
 1953        }
 54
 955        return true;
 1756    }
 57}

Methods/Properties

IsPalindrome(System.Int32)