LeetCode刷题记
来源:互联网 发布:适合开发的linux系统 编辑:程序博客网 时间:2024/05/16 09:33
Maximum Depth of Binary Tree
/** * 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) { int maxDepth = 0, depthLeft = 0, depthRight = 0; if(root == null) return 0; maxDepth = 1; if(root.left != null){ depthLeft += maxDepth(root.left); } if(root.right != null){ depthRight += maxDepth(root.right); } maxDepth += ((depthLeft > depthRight) ? depthLeft : depthRight); return maxDepth; }}
0 0
- LeetCode刷题记
- leetcode刷题记录
- LeetCode刷题记
- LeetCode刷题记 2
- LeetCode刷题记 3
- leetcode刷题记录
- leetcode刷题记录
- leetcode 刷题记
- leetcode 刷题记录
- leetcode刷题记录
- Leetcode刷题记录
- Leetcode刷题记录
- Leetcode刷题记
- leetcode 刷题记录
- LeetCode刷题记录
- 【LeetCode刷题记录】
- leetCode 刷题记录 Candy
- LeetCode 刷题记录 目录
- 【无限互联】ios开发之图文混排研究
- SDUTOJ 2119 数据结构实验之链表四:有序链表的归并
- 重建二叉树
- OpenCV入门(一)
- C语言中static关键字的作用
- LeetCode刷题记
- [C#]委托和事件(详细讲解)
- Linux c 开发 - 进程间通信
- 关于VC编程中出现的APPCRASH
- OpenGL4.x 学习笔记:安装&配置 - preparation
- python中的修饰器
- socket的定义与使用场景
- STL之pair类型详细分析
- I++,I--,++I,--I