< Summary

Information
Class: LeetCode.Algorithms.FindElementsInContaminatedBinaryTree.FindElementsInContaminatedBinaryTreeDepthFirstSearch
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindElementsInContaminatedBinaryTree\FindElementsInContaminatedBinaryTreeDepthFirstSearch.cs
Line coverage
100%
Covered lines: 22
Uncovered lines: 0
Coverable lines: 22
Total lines: 62
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
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%
Find(...)100%88100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindElementsInContaminatedBinaryTree\FindElementsInContaminatedBinaryTreeDepthFirstSearch.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 FindElementsInContaminatedBinaryTreeDepthFirstSearch : IFindElementsInContaminatedBinaryTree
 18{
 19    private readonly TreeNode _root;
 20
 21    /// <summary>
 22    ///     Time complexity - O(1)
 23    ///     Space complexity - O(1)
 24    /// </summary>
 25    /// <param name="root"></param>
 326    public FindElementsInContaminatedBinaryTreeDepthFirstSearch(TreeNode root)
 327    {
 328        _root = root;
 329        _root.val = 0;
 330    }
 31
 32    /// <summary>
 33    ///     Time complexity - O(log n)
 34    ///     Space complexity - O(log n)
 35    /// </summary>
 36    /// <param name="target"></param>
 37    /// <returns></returns>
 38    public bool Find(int target)
 939    {
 940        var node = _root;
 941        var stack = new Stack<bool>();
 42
 2343        while (target > 0)
 1444        {
 1445            stack.Push(target % 2 == 1);
 46
 1447            target = (target - 1) / 2;
 1448        }
 49
 1750        while (stack.Count > 0)
 1251        {
 1252            node = stack.Pop() ? node.left : node.right;
 53
 1254            if (node == null)
 455            {
 456                return false;
 57            }
 858        }
 59
 560        return true;
 961    }
 62}