< Summary

Information
Class: LeetCode.Algorithms.ValidParenthesisString.ValidParenthesisStringIterative
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\ValidParenthesisString\ValidParenthesisStringIterative.cs
Line coverage
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 67
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CheckValidString(...)100%1212100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\ValidParenthesisString\ValidParenthesisStringIterative.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.ValidParenthesisString;
 13
 14/// <inheritdoc />
 15public class ValidParenthesisStringIterative : IValidParenthesisString
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="s"></param>
 22    /// <returns></returns>
 23    public bool CheckValidString(string s)
 1024    {
 1025        var minLeftCount = 0;
 1026        var maxLeftCount = 0;
 27
 37428        foreach (var c in s)
 17329        {
 17330            switch (c)
 31            {
 32                case '(':
 7433                    minLeftCount++;
 7434                    maxLeftCount++;
 7435                    break;
 36                case ')':
 5637                    {
 5638                        if (minLeftCount > 0)
 4139                        {
 4140                            minLeftCount--;
 4141                        }
 42
 5643                        maxLeftCount--;
 44
 5645                        if (maxLeftCount < 0)
 246                        {
 247                            return false;
 48                        }
 49
 5450                        break;
 51                    }
 52                case '*':
 4353                    {
 4354                        if (minLeftCount > 0)
 3055                        {
 3056                            minLeftCount--;
 3057                        }
 58
 4359                        maxLeftCount++;
 4360                        break;
 61                    }
 62            }
 17163        }
 64
 865        return minLeftCount == 0;
 1066    }
 67}

Methods/Properties

CheckValidString(System.String)