< Summary

Information
Class: LeetCode.Algorithms.ReplaceWords.ReplaceWordsBruteForce
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\ReplaceWords\ReplaceWordsBruteForce.cs
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 48
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
ReplaceWords(...)100%66100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\ReplaceWords\ReplaceWordsBruteForce.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.ReplaceWords;
 13
 14/// <inheritdoc />
 15public class ReplaceWordsBruteForce : IReplaceWords
 16{
 17    /// <summary>
 18    ///     Time complexity - O(m + n log n + k * n * L), where n is the number of words in the dictionary, m is the len
 19    ///     the sentence, k is the number of words in the sentence, and L is the length of the longest word
 20    ///     Space complexity - O(m + n), where n is the number of words in the dictionary, m is the length of the senten
 21    /// </summary>
 22    /// <param name="dictionary"></param>
 23    /// <param name="sentence"></param>
 24    /// <returns></returns>
 25    public string ReplaceWords(IList<string> dictionary, string sentence)
 626    {
 627        var words = sentence.Split(' ');
 28
 6829        for (var i = 0; i < words.Length; i++)
 2830        {
 2831            var word = words[i];
 32
 17533            foreach (var dictionaryWord in dictionary.Order())
 5534            {
 5535                if (!word.StartsWith(dictionaryWord))
 3636                {
 3637                    continue;
 38                }
 39
 1940                words[i] = dictionaryWord;
 41
 1942                break;
 43            }
 2844        }
 45
 646        return string.Join(' ', words);
 647    }
 48}