< Summary

Information
Class: LeetCode.Algorithms.CheckIfStringIsPrefixOfArray.CheckIfStringIsPrefixOfArrayTwoPointers
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CheckIfStringIsPrefixOfArray\CheckIfStringIsPrefixOfArrayTwoPointers.cs
Line coverage
95%
Covered lines: 19
Uncovered lines: 1
Coverable lines: 20
Total lines: 53
Line coverage: 95%
Branch coverage
90%
Covered branches: 9
Total branches: 10
Branch coverage: 90%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
IsPrefixString(...)90%101095%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CheckIfStringIsPrefixOfArray\CheckIfStringIsPrefixOfArrayTwoPointers.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.CheckIfStringIsPrefixOfArray;
 13
 14/// <inheritdoc />
 15public class CheckIfStringIsPrefixOfArrayTwoPointers : ICheckIfStringIsPrefixOfArray
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="s"></param>
 22    /// <param name="words"></param>
 23    /// <returns></returns>
 24    public bool IsPrefixString(string s, string[] words)
 325    {
 326        var sIndex = 0;
 27
 1628        foreach (var word in words)
 529        {
 4530            foreach (var letter in word)
 1631            {
 1632                if (sIndex == s.Length)
 133                {
 134                    return false;
 35                }
 36
 1537                if (s[sIndex] != letter)
 138                {
 139                    return false;
 40                }
 41
 1442                sIndex++;
 1443            }
 44
 345            if (sIndex == s.Length)
 146            {
 147                return true;
 48            }
 249        }
 50
 051        return sIndex == s.Length;
 352    }
 53}