< Summary

Information
Class: LeetCode.Algorithms.FindCorrespondingNodeOfBinaryTreeInCloneOfThatTree.FindCorrespondingNodeOfBinaryTreeInCloneOfThatTreeBreadthFirstSearch
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindCorrespondingNodeOfBinaryTreeInCloneOfThatTree\FindCorrespondingNodeOfBinaryTreeInCloneOfThatTreeBreadthFirstSearch.cs
Line coverage
91%
Covered lines: 31
Uncovered lines: 3
Coverable lines: 34
Total lines: 74
Line coverage: 91.1%
Branch coverage
77%
Covered branches: 14
Total branches: 18
Branch coverage: 77.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
GetTargetCopy(...)77.77%181891.17%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindCorrespondingNodeOfBinaryTreeInCloneOfThatTree\FindCorrespondingNodeOfBinaryTreeInCloneOfThatTreeBreadthFirstSearch.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.FindCorrespondingNodeOfBinaryTreeInCloneOfThatTree;
 15
 16/// <inheritdoc />
 17public class FindCorrespondingNodeOfBinaryTreeInCloneOfThatTreeBreadthFirstSearch :
 18    IFindCorrespondingNodeOfBinaryTreeInCloneOfThatTree
 19{
 20    /// <summary>
 21    ///     Time complexity - O(n)
 22    ///     Space complexity - O(n)
 23    /// </summary>
 24    /// <param name="original"></param>
 25    /// <param name="cloned"></param>
 26    /// <param name="target"></param>
 27    /// <returns></returns>
 28    public TreeNode? GetTargetCopy(TreeNode? original, TreeNode? cloned, TreeNode? target)
 329    {
 330        if (original == null || cloned == null || target == null)
 031        {
 032            return null;
 33        }
 34
 335        var originalQueue = new Queue<TreeNode>();
 336        var clonedQueue = new Queue<TreeNode>();
 37
 338        originalQueue.Enqueue(original);
 339        clonedQueue.Enqueue(cloned);
 40
 841        while (originalQueue.Count > 0)
 842        {
 843            var originalNode = originalQueue.Dequeue();
 844            var clonedNode = clonedQueue.Dequeue();
 45
 846            if (originalNode.Equals(target))
 347            {
 348                return clonedNode;
 49            }
 50
 551            if (originalNode.left != null)
 152            {
 153                originalQueue.Enqueue(originalNode.left);
 154            }
 55
 556            if (originalNode.right != null)
 457            {
 458                originalQueue.Enqueue(originalNode.right);
 459            }
 60
 561            if (clonedNode.left != null)
 162            {
 163                clonedQueue.Enqueue(clonedNode.left);
 164            }
 65
 566            if (clonedNode.right != null)
 467            {
 468                clonedQueue.Enqueue(clonedNode.right);
 469            }
 570        }
 71
 072        return null;
 373    }
 74}