< Summary

Information
Class: LeetCode.Algorithms.UniqueMorseCodeWords.UniqueMorseCodeWordsHashSet
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\UniqueMorseCodeWords\UniqueMorseCodeWordsHashSet.cs
Line coverage
100%
Covered lines: 42
Uncovered lines: 0
Coverable lines: 42
Total lines: 73
Line coverage: 100%
Branch coverage
100%
Covered branches: 4
Total branches: 4
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor()100%11100%
UniqueMorseRepresentations(...)100%44100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\UniqueMorseCodeWords\UniqueMorseCodeWordsHashSet.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.UniqueMorseCodeWords;
 15
 16/// <inheritdoc />
 17public class UniqueMorseCodeWordsHashSet : IUniqueMorseCodeWords
 18{
 219    private readonly Dictionary<char, string> _morseCodeDictionary = new()
 220    {
 221        { 'a', ".-" },
 222        { 'b', "-..." },
 223        { 'c', "-.-." },
 224        { 'd', "-.." },
 225        { 'e', "." },
 226        { 'f', "..-." },
 227        { 'g', "--." },
 228        { 'h', "...." },
 229        { 'i', ".." },
 230        { 'j', ".---" },
 231        { 'k', "-.-" },
 232        { 'l', ".-.." },
 233        { 'm', "--" },
 234        { 'n', "-." },
 235        { 'o', "---" },
 236        { 'p', ".--." },
 237        { 'q', "--.-" },
 238        { 'r', ".-." },
 239        { 's', "..." },
 240        { 't', "-" },
 241        { 'u', "..-" },
 242        { 'v', "...-" },
 243        { 'w', ".--" },
 244        { 'x', "-..-" },
 245        { 'y', "-.--" },
 246        { 'z', "--.." }
 247    };
 48
 49    /// <summary>
 50    ///     Time complexity - O(n * m)
 51    ///     Space complexity - O(n * m)
 52    /// </summary>
 53    /// <param name="words"></param>
 54    /// <returns></returns>
 55    public int UniqueMorseRepresentations(string[] words)
 256    {
 257        var morseRepresentationsHashSet = new HashSet<string>();
 58
 1659        foreach (var word in words)
 560        {
 561            var morseCodeWordStringBuilder = new StringBuilder();
 62
 5463            foreach (var morseCode in word.Select(@char => _morseCodeDictionary[@char]))
 1364            {
 1365                morseCodeWordStringBuilder.Append(morseCode);
 1366            }
 67
 568            morseRepresentationsHashSet.Add(morseCodeWordStringBuilder.ToString());
 569        }
 70
 271        return morseRepresentationsHashSet.Count;
 272    }
 73}