< Summary

Information
Class: LeetCode.Algorithms.PushDominoes.PushDominoesTwoPointers
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\PushDominoes\PushDominoesTwoPointers.cs
Line coverage
100%
Covered lines: 37
Uncovered lines: 0
Coverable lines: 37
Total lines: 71
Line coverage: 100%
Branch coverage
100%
Covered branches: 20
Total branches: 20
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
PushDominoes(...)100%2020100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\PushDominoes\PushDominoesTwoPointers.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.PushDominoes;
 13
 14/// <inheritdoc />
 15public class PushDominoesTwoPointers : IPushDominoes
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(n)
 20    /// </summary>
 21    /// <param name="dominoes"></param>
 22    /// <returns></returns>
 23    public string PushDominoes(string dominoes)
 224    {
 225        var dominoesCharArray = dominoes.ToCharArray();
 26
 227        var left = -1;
 28
 4429        for (var right = 0; right <= dominoesCharArray.Length; right++)
 2030        {
 2031            var current = right < dominoesCharArray.Length ? dominoesCharArray[right] : 'R';
 2032            var previous = left >= 0 ? dominoesCharArray[left] : 'L';
 33
 2034            if (current == '.')
 1035            {
 1036                continue;
 37            }
 38
 1039            if (right - left > 1)
 640            {
 641                var currentLeft = left + 1;
 642                var currentRight = right - 1;
 43
 644                if (previous == current)
 145                {
 246                    while (currentLeft <= currentRight)
 147                    {
 148                        dominoesCharArray[currentLeft] = current;
 49
 150                        currentLeft++;
 151                    }
 152                }
 553                else if (previous == 'R' && current == 'L')
 354                {
 555                    while (currentLeft < currentRight)
 256                    {
 257                        dominoesCharArray[currentLeft] = 'R';
 258                        dominoesCharArray[currentRight] = 'L';
 59
 260                        currentLeft++;
 261                        currentRight--;
 262                    }
 363                }
 664            }
 65
 1066            left = right;
 1067        }
 68
 269        return new string(dominoesCharArray);
 270    }
 71}

Methods/Properties

PushDominoes(System.String)