博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
104. Maximum Depth of Binary Tree
阅读量:4695 次
发布时间:2019-06-09

本文共 625 字,大约阅读时间需要 2 分钟。

Problem:

Given a binary tree, find its maximum depth.

The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node.

 

Solution:

/** * Definition for a binary tree node. * struct TreeNode { *     int val; *     struct TreeNode *left; *     struct TreeNode *right; * }; */int maxDepth(struct TreeNode* root) {    int left_depth,right_depth;    if(root == NULL)        return 0;    left_depth = maxDepth(root->left);    right_depth= maxDepth(root->right);    return (left_depth>right_depth)?left_depth+1:right_depth+1;}

  

转载于:https://www.cnblogs.com/liutianyi10/p/5521210.html

你可能感兴趣的文章
Oracle 组函数count()
查看>>
Session的使用过程中应注意的一个小问题
查看>>
SDK,API,DLL名词解释
查看>>
试探算法
查看>>
安恒杯七月赛题
查看>>
世界著名logo设计文化解读
查看>>
统计学习方法[6]——逻辑回归模型
查看>>
体验课:开启算法之旅
查看>>
17.28搭建项目开发环境
查看>>
day38 07-Spring框架Bean的时候方式
查看>>
day39-Spring 13-Spring的JDBC模板:默认连接池的配置
查看>>
hdu 2058 The sum problem
查看>>
[wp7游戏]wp7~~X-Box Live游戏~~集合贴~~
查看>>
Access 标准表达式中数据类型不匹配问题
查看>>
Python实现屏幕截图
查看>>
【Python求助】在eclipse和pycharm中,通过adb install安装中文名字APK时老是报错,如何解决...
查看>>
用weka来做Logistic Regression
查看>>
Linux现学现用之Top命令
查看>>
[C3W1] Structuring Machine Learning Projects - ML Strategy 1
查看>>
【原创】谈谈服务雪崩、降级与熔断
查看>>