< Summary

Information
Class: LeetCode.Algorithms.ValidWord.ValidWordIterative
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\ValidWord\ValidWordIterative.cs
Line coverage
100%
Covered lines: 28
Uncovered lines: 0
Coverable lines: 28
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
.cctor()100%11100%
IsValid(...)100%1010100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\ValidWord\ValidWordIterative.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.ValidWord;
 13
 14/// <inheritdoc />
 15public class ValidWordIterative : IValidWord
 16{
 117    private static readonly HashSet<char> Vowels =
 118    [
 119        'a', 'e', 'i', 'o', 'u'
 120    ];
 21
 22    /// <summary>
 23    ///     Time complexity - O(n)
 24    ///     Space complexity - O(1)
 25    /// </summary>
 26    /// <param name="word"></param>
 27    /// <returns></returns>
 28    public bool IsValid(string word)
 429    {
 430        if (word.Length < 3)
 131        {
 132            return false;
 33        }
 34
 335        var hasVowel = false;
 336        var hasConsonant = false;
 37
 3438        foreach (var character in word)
 1339        {
 1340            if (!char.IsLetterOrDigit(character))
 141            {
 142                return false;
 43            }
 44
 1245            if (char.IsDigit(character))
 446            {
 447                continue;
 48            }
 49
 850            if (Vowels.Contains(char.ToLower(character)))
 551            {
 552                hasVowel = true;
 553            }
 54            else
 355            {
 356                hasConsonant = true;
 357            }
 858        }
 59
 260        return hasVowel && hasConsonant;
 461    }
 62}

Methods/Properties

.cctor()
IsValid(System.String)