< Summary

Information
Class: LeetCode.Algorithms.MovePiecesToObtainString.MovePiecesToObtainStringTwoPointers
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MovePiecesToObtainString\MovePiecesToObtainStringTwoPointers.cs
Line coverage
78%
Covered lines: 32
Uncovered lines: 9
Coverable lines: 41
Total lines: 82
Line coverage: 78%
Branch coverage
72%
Covered branches: 29
Total branches: 40
Branch coverage: 72.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CanChange(...)72.5%574078.04%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MovePiecesToObtainString\MovePiecesToObtainStringTwoPointers.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.MovePiecesToObtainString;
 13
 14/// <inheritdoc />
 15public class MovePiecesToObtainStringTwoPointers : IMovePiecesToObtainString
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(1)
 20    /// </summary>
 21    /// <param name="start"></param>
 22    /// <param name="target"></param>
 23    /// <returns></returns>
 24    public bool CanChange(string start, string target)
 325    {
 326        var startIndex = 0;
 327        var targetIndex = 0;
 28
 629        while (startIndex < start.Length && targetIndex < target.Length)
 530        {
 1131            while (startIndex < start.Length && start[startIndex] == '_')
 632            {
 633                startIndex++;
 634            }
 35
 1336            while (targetIndex < target.Length && target[targetIndex] == '_')
 837            {
 838                targetIndex++;
 839            }
 40
 541            if (startIndex == start.Length && targetIndex == target.Length)
 042            {
 043                return true;
 44            }
 45
 546            if (startIndex == start.Length || targetIndex == target.Length)
 047            {
 048                return false;
 49            }
 50
 551            if (start[startIndex] != target[targetIndex])
 152            {
 153                return false;
 54            }
 55
 456            if (start[startIndex] == 'L' && targetIndex > startIndex)
 057            {
 058                return false;
 59            }
 60
 461            if (start[startIndex] == 'R' && targetIndex < startIndex)
 162            {
 163                return false;
 64            }
 65
 366            startIndex++;
 367            targetIndex++;
 368        }
 69
 270        while (startIndex < start.Length && start[startIndex] == '_')
 171        {
 172            startIndex++;
 173        }
 74
 175        while (targetIndex < target.Length && target[targetIndex] == '_')
 076        {
 077            targetIndex++;
 078        }
 79
 180        return startIndex == start.Length && targetIndex == target.Length;
 381    }
 82}