< Summary

Information
Class: LeetCode.Algorithms.MakeTheStringGreat.MakeTheStringGreatIterative
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MakeTheStringGreat\MakeTheStringGreatIterative.cs
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 53
Line coverage: 100%
Branch coverage
100%
Covered branches: 14
Total branches: 14
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
MakeGood(...)100%1414100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\MakeTheStringGreat\MakeTheStringGreatIterative.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.MakeTheStringGreat;
 13
 14/// <inheritdoc />
 15public class MakeTheStringGreatIterative : IMakeTheStringGreat
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n^2)
 19    ///     Space complexity - O(n)
 20    /// </summary>
 21    /// <param name="s"></param>
 22    /// <returns></returns>
 23    public string MakeGood(string s)
 524    {
 525        if (s.Length < 2)
 226        {
 227            return s;
 28        }
 29
 330        var sList = s.ToList();
 31
 332        var i = 0;
 33
 2634        while (i < sList.Count - 1)
 2335        {
 2336            if (char.ToLower(sList[i]) == char.ToLower(sList[i + 1]) &&
 2337                ((char.IsLower(sList[i]) && char.IsUpper(sList[i + 1])) ||
 2338                 (char.IsUpper(sList[i]) && char.IsLower(sList[i + 1]))))
 839            {
 840                sList.RemoveAt(i + 1);
 841                sList.RemoveAt(i);
 42
 843                i = 0;
 844            }
 45            else
 1546            {
 1547                i++;
 1548            }
 2349        }
 50
 351        return string.Concat(sList);
 552    }
 53}

Methods/Properties

MakeGood(System.String)