< Summary

Information
Class: LeetCode.Algorithms.SymmetricTree.SymmetricTreeRecursive
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SymmetricTree\SymmetricTreeRecursive.cs
Line coverage
86%
Covered lines: 13
Uncovered lines: 2
Coverable lines: 15
Total lines: 49
Line coverage: 86.6%
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
IsSymmetric(...)100%44100%
IsSymmetric(...)91.66%131283.33%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\SymmetricTree\SymmetricTreeRecursive.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.SymmetricTree;
 15
 16/// <inheritdoc />
 17public class SymmetricTreeRecursive : ISymmetricTree
 18{
 19    /// <summary>
 20    ///     Time complexity - O(n)
 21    ///     Space complexity - O(n)
 22    /// </summary>
 23    /// <param name="root"></param>
 24    /// <returns></returns>
 25    public bool IsSymmetric(TreeNode? root)
 326    {
 327        return IsSymmetric(root?.left, root?.right);
 328    }
 29
 30    private static bool IsSymmetric(TreeNode? left, TreeNode? right)
 1031    {
 1032        if (left == null && right == null)
 533        {
 534            return true;
 35        }
 36
 537        if (left == null || right == null)
 138        {
 139            return false;
 40        }
 41
 442        if (left.val != right.val)
 043        {
 044            return false;
 45        }
 46
 447        return IsSymmetric(left.left, right.right) && IsSymmetric(left.right, right.left);
 1048    }
 49}