< Summary

Information
Class: LeetCode.Algorithms.FlipEquivalentBinaryTrees.FlipEquivalentBinaryTreesRecursive
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FlipEquivalentBinaryTrees\FlipEquivalentBinaryTreesRecursive.cs
Line coverage
100%
Covered lines: 13
Uncovered lines: 0
Coverable lines: 13
Total lines: 46
Line coverage: 100%
Branch coverage
93%
Covered branches: 15
Total branches: 16
Branch coverage: 93.7%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
FlipEquiv(...)93.75%1616100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FlipEquivalentBinaryTrees\FlipEquivalentBinaryTreesRecursive.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.FlipEquivalentBinaryTrees;
 15
 16/// <inheritdoc />
 17public class FlipEquivalentBinaryTreesRecursive : IFlipEquivalentBinaryTrees
 18{
 19    /// <summary>
 20    ///     Time complexity - O(n)
 21    ///     Space complexity - O(n)
 22    /// </summary>
 23    /// <param name="root1"></param>
 24    /// <param name="root2"></param>
 25    /// <returns></returns>
 26    public bool FlipEquiv(TreeNode? root1, TreeNode? root2)
 2227    {
 2228        if (root1 == null && root2 == null)
 1029        {
 1030            return true;
 31        }
 32
 1233        if (root1 == null || root2 == null)
 234        {
 235            return false;
 36        }
 37
 1038        if (root1.val != root2.val)
 239        {
 240            return false;
 41        }
 42
 843        return (FlipEquiv(root1.left, root2.left) && FlipEquiv(root1.right, root2.right)) ||
 844               (FlipEquiv(root1.left, root2.right) && FlipEquiv(root1.right, root2.left));
 2245    }
 46}