LCOV - code coverage report
Current view: top level - src/src - 104.maximum-depth-of-binary-tree.cpp (source / functions) Coverage Total Hit
Test: _coverage_report.dat Lines: 100.0 % 8 8
Test Date: 2026-05-12 16:09:00 Functions: 100.0 % 5 5

            Line data    Source code
       1              : // Copyright (c) 2023 The Authors. All rights reserved.
       2              : //
       3              : // Licensed under the Apache License, Version 2.0 (the "License");
       4              : // you may not use this file except in compliance with the License.
       5              : // You may obtain a copy of the License at
       6              : //
       7              : //      https://www.apache.org/licenses/LICENSE-2.0
       8              : //
       9              : // Unless required by applicable law or agreed to in writing, software
      10              : // distributed under the License is distributed on an "AS IS" BASIS,
      11              : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      12              : // See the License for the specific language governing permissions and
      13              : // limitations under the License.
      14              : 
      15              : // Authors: liubang (it.liubang@gmail.com)
      16              : // Created: 2023/11/30 23:08
      17              : 
      18              : #include <gtest/gtest.h>
      19              : 
      20              : #include "tree.h"
      21              : 
      22              : namespace {
      23              : class Solution {
      24              : public:
      25              :     using TreeNode = leetcode::tree::TreeNode;
      26           11 :     int maxDepth(TreeNode* root) {
      27           22 :         return root == nullptr ? 0 : std::max(maxDepth(root->left), maxDepth(root->right)) + 1;
      28              :     }
      29              : };
      30              : } // namespace
      31              : 
      32            4 : TEST(Leetcode, maximum_depth_of_binary_tree) {
      33              :     using TreeNode = leetcode::tree::TreeNode;
      34            1 :     Solution s;
      35              :     TreeNode* root =
      36            1 :         new TreeNode(3, new TreeNode(9), new TreeNode(20, new TreeNode(15), new TreeNode(7)));
      37              : 
      38            1 :     EXPECT_EQ(3, s.maxDepth(root));
      39            1 :     leetcode::tree::destroy(root);
      40            1 : }
        

Generated by: LCOV version 2.0-1