< Summary

Information
Class: LeetCode.Algorithms.DeleteCharactersToMakeFancyString.DeleteCharactersToMakeFancyStringIterative
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\DeleteCharactersToMakeFancyString\DeleteCharactersToMakeFancyStringIterative.cs
Line coverage
100%
Covered lines: 23
Uncovered lines: 0
Coverable lines: 23
Total lines: 58
Line coverage: 100%
Branch coverage
100%
Covered branches: 6
Total branches: 6
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
MakeFancyString(...)100%66100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\DeleteCharactersToMakeFancyString\DeleteCharactersToMakeFancyStringIterative.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
 12using System.Text;
 13
 14namespace LeetCode.Algorithms.DeleteCharactersToMakeFancyString;
 15
 16/// <inheritdoc />
 17public class DeleteCharactersToMakeFancyStringIterative : IDeleteCharactersToMakeFancyString
 18{
 19    /// <summary>
 20    ///     Time complexity - O(n)
 21    ///     Space complexity - O(n)
 22    /// </summary>
 23    /// <param name="s"></param>
 24    /// <returns></returns>
 25    public string MakeFancyString(string s)
 326    {
 327        var resultStringBuilder = new StringBuilder();
 28
 329        resultStringBuilder.Append(s[0]);
 30
 331        var previous = s[0];
 332        var count = 1;
 33
 4034        for (var i = 1; i < s.Length; i++)
 1735        {
 1736            if (s[i] == previous)
 837            {
 838                if (count == 2)
 439                {
 440                    continue;
 41                }
 42
 443                resultStringBuilder.Append(s[i]);
 44
 445                count++;
 446            }
 47            else
 948            {
 949                resultStringBuilder.Append(s[i]);
 50
 951                previous = s[i];
 952                count = 1;
 953            }
 1354        }
 55
 356        return resultStringBuilder.ToString();
 357    }
 58}

Methods/Properties

MakeFancyString(System.String)