[LeetCode OJ]Maximum Depth Of Binary Tree
来源:互联网 发布:域名ip查询 编辑:程序博客网 时间:2024/06/04 19:56
Given two binary trees, write a function to check if they are equal or not.
Two binary trees are considered equal if they are structurally identical and the nodes have the same value.
貌似就是个二叉树深度,早就忘得透透的了,又回去看了看,这个递归想了好久好久唉。。。
Java版本
/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution { public int maxDepth(TreeNode root) { if(root == null) { return 0; } int left = maxDepth(root.left); int right = maxDepth(root.right); return left > right ? left + 1 : right + 1; }}最后这个还可以调用java max
return max(left, right) + 1;
C++版本
/** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(x), left(NULL), right(NULL) {} * }; */class Solution {public: int maxDepth(TreeNode *root) { if(root == NULL) return 0; int left = maxDepth(root->left); int right = maxDepth(root->right); return left > right ? left + 1 : right + 1; }};
0 0
- [LeetCode OJ]Maximum Depth of Binary Tree
- LeetCode OJ:Maximum Depth of Binary Tree
- LeetCode OJ - Maximum Depth of Binary Tree
- [LeetCode OJ]Maximum Depth Of Binary Tree
- LeetCode OJ Maximum Depth of Binary Tree
- <LeetCode OJ> (104 / 111) Maximum & Minimum Depth of Binary Tree
- LeetCode OJ : 104. Maximum Depth of Binary Tree
- LeetCode oj 104. Maximum Depth of Binary Tree(DFS||BFS)
- Leetcode - Tree - Maximum Depth of Binary Tree
- [leetcode][tree] Maximum Depth of Binary Tree
- LeetCode Maximum Depth of Binary Tree
- [Leetcode] Maximum Depth of Binary Tree
- leetcode 24: Maximum Depth of Binary Tree
- [LeetCode] Maximum Depth of Binary Tree
- Leetcode 104 Maximum Depth of Binary Tree
- 【leetcode】Maximum Depth of Binary Tree
- [leetcode]Maximum Depth of Binary Tree
- [LeetCode]Maximum Depth of Binary Tree
- 黑马程序员----多线程学习笔记
- Django中使用admin的多选widget插件FilteredSelectMultiple
- 动漫_网球优等生の片尾曲_ベイビーステップ(Baby-Steps)(国语日语对照)
- ubuntu14.04下android开发环境的搭建5-1 :概述
- uvalive 2326(贪心)
- [LeetCode OJ]Maximum Depth Of Binary Tree
- NYOJ 286【动物统计】 STL
- poj2828--Buy Tickets(线段树+详解)
- ubunto xdebug
- IBM system x5服务器利用webBios 配置磁盘阵列RAID
- 3——FFMPEG之解复用器-----AVInputFormat
- Android事件传递机制
- 数的划分 wikioj 1039
- Implicit super constructor xx() is undefined for default constructor. Must define an explicit constr