< Summary

Information
Class: LeetCode.Algorithms.FinalValueOfVariableAfterPerformingOperations.FinalValueOfVariableAfterPerformingOperationsDictionary
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FinalValueOfVariableAfterPerformingOperations\FinalValueOfVariableAfterPerformingOperationsDictionary.cs
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 41
Line coverage: 100%
Branch coverage
100%
Covered branches: 2
Total branches: 2
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%
FinalValueAfterOperations(...)100%22100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FinalValueOfVariableAfterPerformingOperations\FinalValueOfVariableAfterPerformingOperationsDictionary.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.FinalValueOfVariableAfterPerformingOperations;
 13
 14/// <inheritdoc />
 15public class FinalValueOfVariableAfterPerformingOperationsDictionary : IFinalValueOfVariableAfterPerformingOperations
 16{
 317    private readonly Dictionary<string, int> _operationsDictionary = new()
 318    {
 319        { "++X", 1 }, { "X++", 1 }, { "--X", -1 }, { "X--", -1 }
 320    };
 21
 22    /// <summary>
 23    ///     Time complexity - O(n)
 24    ///     Space complexity - O(1)
 25    /// </summary>
 26    /// <param name="operations"></param>
 27    /// <returns></returns>
 28    public int FinalValueAfterOperations(string[] operations)
 329    {
 330        var finalValue = 0;
 31
 2932        foreach (var operation in operations)
 1033        {
 1034            _operationsDictionary.TryGetValue(operation, out var value);
 35
 1036            finalValue += value;
 1037        }
 38
 339        return finalValue;
 340    }
 41}