< Summary

Information
Class: LeetCode.Algorithms.FindBottomLeftTreeValue.FindBottomLeftTreeValueDepthFirst
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindBottomLeftTreeValue\FindBottomLeftTreeValueDepthFirst.cs
Line coverage
100%
Covered lines: 19
Uncovered lines: 0
Coverable lines: 19
Total lines: 53
Line coverage: 100%
Branch coverage
100%
Covered branches: 12
Total branches: 12
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
FindBottomLeftValue(...)100%22100%
FindBottomLeftValue(...)100%1010100%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\FindBottomLeftTreeValue\FindBottomLeftTreeValueDepthFirst.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.FindBottomLeftTreeValue;
 15
 16/// <inheritdoc />
 17public class FindBottomLeftTreeValueDepthFirst : IFindBottomLeftTreeValue
 18{
 19    /// <summary>
 20    ///     Time complexity - O(n)
 21    ///     Space complexity - O(log n) for a balanced tree, O(n) for a skewed tree
 22    /// </summary>
 23    /// <param name="root"></param>
 24    /// <returns></returns>
 25    public int FindBottomLeftValue(TreeNode? root)
 526    {
 527        return root == null ? 0 : FindBottomLeftValue(root, 0).Item1;
 528    }
 29
 30    private static (int, int) FindBottomLeftValue(TreeNode root, int lastRow)
 2231    {
 2232        if (root.left == null && root.right == null)
 1033        {
 1034            return (root.val, lastRow);
 35        }
 36
 1237        var leftValue = (0, 0);
 38
 1239        if (root.left != null)
 1040        {
 1041            leftValue = FindBottomLeftValue(root.left, lastRow + 1);
 1042        }
 43
 1244        var rightValue = (0, 0);
 45
 1246        if (root.right != null)
 847        {
 848            rightValue = FindBottomLeftValue(root.right, lastRow + 1);
 849        }
 50
 1251        return leftValue.Item2 >= rightValue.Item2 ? leftValue : rightValue;
 2252    }
 53}