< Summary

Information
Class: LeetCode.Algorithms.CheckIfNAndItsDoubleExist.CheckIfNAndItsDoubleExistDictionary
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CheckIfNAndItsDoubleExist\CheckIfNAndItsDoubleExistDictionary.cs
Line coverage
100%
Covered lines: 29
Uncovered lines: 0
Coverable lines: 29
Total lines: 61
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
CheckIfExist(...)100%1212100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\CheckIfNAndItsDoubleExist\CheckIfNAndItsDoubleExistDictionary.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.CheckIfNAndItsDoubleExist;
 13
 14/// <inheritdoc />
 15public class CheckIfNAndItsDoubleExistDictionary : ICheckIfNAndItsDoubleExist
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(n)
 20    /// </summary>
 21    /// <param name="arr"></param>
 22    /// <returns></returns>
 23    public bool CheckIfExist(int[] arr)
 524    {
 525        var dictionary = new Dictionary<int, int>();
 26
 5927        foreach (var item in arr)
 2228        {
 2229            if (dictionary.TryGetValue(item, out var value))
 130            {
 131                dictionary[item] = value + 1;
 132            }
 33            else
 2134            {
 2135                dictionary.Add(item, 1);
 2136            }
 2237        }
 38
 4439        foreach (var item in arr)
 1640        {
 1641            if (item != 0)
 1442            {
 1443                if (dictionary.ContainsKey(item * 2))
 244                {
 245                    return true;
 46                }
 1247            }
 48            else
 249            {
 250                dictionary.TryGetValue(item, out var value);
 51
 252                if (value > 1)
 153                {
 154                    return true;
 55                }
 156            }
 1357        }
 58
 259        return false;
 560    }
 61}

Methods/Properties

CheckIfExist(System.Int32[])