< Summary

Information
Class: LeetCode.Algorithms.FindCenterOfStarGraph.FindCenterOfStarGraphDictionary
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindCenterOfStarGraph\FindCenterOfStarGraphDictionary.cs
Line coverage
94%
Covered lines: 17
Uncovered lines: 1
Coverable lines: 18
Total lines: 47
Line coverage: 94.4%
Branch coverage
90%
Covered branches: 9
Total branches: 10
Branch coverage: 90%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
FindCenter(...)90%101094.44%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindCenterOfStarGraph\FindCenterOfStarGraphDictionary.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.FindCenterOfStarGraph;
 13
 14/// <inheritdoc />
 15public class FindCenterOfStarGraphDictionary : IFindCenterOfStarGraph
 16{
 17    /// <summary>
 18    ///     Time complexity - O(n)
 19    ///     Space complexity - O(n)
 20    /// </summary>
 21    /// <param name="edges"></param>
 22    /// <returns></returns>
 23    public int FindCenter(int[][] edges)
 224    {
 225        var dictionary = new Dictionary<int, int>();
 26
 2027        foreach (var edge in edges)
 728        {
 729            if (!dictionary.TryAdd(edge[0], 1))
 330            {
 331                dictionary[edge[0]]++;
 332            }
 33
 734            if (!dictionary.TryAdd(edge[1], 1))
 235            {
 236                dictionary[edge[1]]++;
 237            }
 738        }
 39
 1140        foreach (var item in dictionary.Where(item => item.Value == edges.Length))
 241        {
 242            return item.Key;
 43        }
 44
 045        return -1;
 246    }
 47}

Methods/Properties

FindCenter(System.Int32[][])