< Summary

Information
Class: LeetCode.Algorithms.IsSubsequence.IsSubsequenceTwoPointers
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\IsSubsequence\IsSubsequenceTwoPointers.cs
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 51
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
IsSubsequence(...)100%88100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\IsSubsequence\IsSubsequenceTwoPointers.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.IsSubsequence;
 13
 14/// <inheritdoc />
 15public class IsSubsequenceTwoPointers : IIsSubsequence
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n + m)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="s"></param>
 22    /// <param name="t"></param>
 23    /// <returns></returns>
 24    public bool IsSubsequence(string s, string t)
 725    {
 726        if (s.Length == 0)
 127        {
 128            return true;
 29        }
 30
 631        var sIndex = 0;
 632        var tIndex = 0;
 33
 103134        while (tIndex < t.Length)
 102735        {
 102736            if (t[tIndex] == s[sIndex])
 1337            {
 1338                sIndex++;
 39
 1340                if (sIndex == s.Length)
 241                {
 242                    return true;
 43                }
 1144            }
 45
 102546            tIndex++;
 102547        }
 48
 449        return false;
 750    }
 51}