< Summary

Information
Class: LeetCode.Algorithms.FindElementsInContaminatedBinaryTree.FindElementsInContaminatedBinaryTreeHashSet
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindElementsInContaminatedBinaryTree\FindElementsInContaminatedBinaryTreeHashSet.cs
Line coverage
100%
Covered lines: 25
Uncovered lines: 0
Coverable lines: 25
Total lines: 66
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
.ctor(...)100%66100%
Find(...)100%11100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindElementsInContaminatedBinaryTree\FindElementsInContaminatedBinaryTreeHashSet.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 LeetCode.Core.Models;
 13
 14namespace LeetCode.Algorithms.FindElementsInContaminatedBinaryTree;
 15
 16/// <inheritdoc />
 17public class FindElementsInContaminatedBinaryTreeHashSet : IFindElementsInContaminatedBinaryTree
 18{
 319    private readonly HashSet<int> _hashSet = [];
 20
 21    /// <summary>
 22    ///     Time complexity - O(n)
 23    ///     Space complexity - O(n)
 24    /// </summary>
 25    /// <param name="root"></param>
 326    public FindElementsInContaminatedBinaryTreeHashSet(TreeNode root)
 327    {
 328        var queue = new Queue<TreeNode>();
 29
 330        root.val = 0;
 31
 332        queue.Enqueue(root);
 33
 1434        while (queue.Count > 0)
 1135        {
 1136            var treeNode = queue.Dequeue();
 37
 1138            _hashSet.Add(treeNode.val);
 39
 1140            if (treeNode.left != null)
 441            {
 442                treeNode.left.val = (2 * treeNode.val) + 1;
 43
 444                queue.Enqueue(treeNode.left);
 445            }
 46
 1147            if (treeNode.right != null)
 448            {
 449                treeNode.right.val = (2 * treeNode.val) + 2;
 50
 451                queue.Enqueue(treeNode.right);
 452            }
 1153        }
 354    }
 55
 56    /// <summary>
 57    ///     Time complexity - O(1)
 58    ///     Space complexity - O(1)
 59    /// </summary>
 60    /// <param name="target"></param>
 61    /// <returns></returns>
 62    public bool Find(int target)
 963    {
 964        return _hashSet.Contains(target);
 965    }
 66}