< Summary

Information
Class: LeetCode.Algorithms.RangeSumOfBST.RangeSumOfBSTDepthFirstSearchRecursive
Assembly: LeetCode
File(s): D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\RangeSumOfBST\RangeSumOfBSTDepthFirstSearchRecursive.cs
Line coverage
89%
Covered lines: 17
Uncovered lines: 2
Coverable lines: 19
Total lines: 53
Line coverage: 89.4%
Branch coverage
90%
Covered branches: 9
Total branches: 10
Branch coverage: 90%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
RangeSumBST(...)90%101089.47%

File(s)

D:\a\LeetCode-CS\LeetCode-CS\source\LeetCode\Algorithms\RangeSumOfBST\RangeSumOfBSTDepthFirstSearchRecursive.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.RangeSumOfBST;
 15
 16/// <inheritdoc />
 17public class RangeSumOfBSTDepthFirstSearchRecursive : IRangeSumOfBST
 18{
 19    /// <summary>
 20    ///     Time complexity - O(n)
 21    ///     Space complexity - O(h), where h is the height of the tree
 22    /// </summary>
 23    /// <param name="root"></param>
 24    /// <param name="low"></param>
 25    /// <param name="high"></param>
 26    /// <returns></returns>
 27    public int RangeSumBST(TreeNode? root, int low, int high)
 1528    {
 1529        if (root == null)
 030        {
 031            return 0;
 32        }
 33
 1534        var result = 0;
 35
 1536        if (root.val >= low && root.val <= high)
 637        {
 638            result += root.val;
 639        }
 40
 1541        if (root.left != null)
 742        {
 743            result += RangeSumBST(root.left, low, high);
 744        }
 45
 1546        if (root.right != null)
 647        {
 648            result += RangeSumBST(root.right, low, high);
 649        }
 50
 1551        return result;
 1552    }
 53}