LeetCode刷题(C++)——Minimum Depth if Binary Tree(Easy)
来源:互联网 发布:帝国cms 自动生成标签 编辑:程序博客网 时间:2024/05/22 00:19
题目描述
Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.
/*Definition for binary treestruct TreeNode{int val;TreeNode* left;TreeNode* right;TreeNode(int x):val(x),left(NULL),right(NULL){}};*/class Solution {public:int getDepth(TreeNode* p){if (p == NULL)return 0;if (p->left == NULL&&p->right == NULL)return 1;int LD = INT_MAX;int RD = INT_MAX;if (p->left)LD = getDepth(p->left)+1;if (p->right)RD = getDepth(p->right)+1;return (LD > RD) ? RD : LD;}int run(TreeNode *root) {int mindepth = getDepth(root);return mindepth;}};
0 0
- LeetCode刷题(C++)——Minimum Depth if Binary Tree(Easy)
- Minimum Depth of Binary Tree——LeetCode(Easy)
- LeetCode刷题(C++)——Maximum Depth of Binary Tree(Easy)
- LeetCode-Easy刷题(25) Minimum Depth of Binary Tree
- 【leetcode】111. Minimum Depth of Binary Tree(Python & C++)
- leetcode minimum depth(binary tree)
- minimum-depth-of-binary-tree(Leetcode)
- [Leetcode 104, Easy] Minimum (Maximum) Depth of Binary Tree
- [Leetcode 111, Easy] Minimum Depth of Binary Tree
- <LeetCode><Easy> 111 Minimum Depth of Binary Tree
- Leetcode 111. Minimum Depth of Binary Tree (Easy) (cpp)
- LeetCode解题报告 111. Minimum Depth of Binary Tree [easy]
- 【Leetcode-easy-111】Minimum Depth of Binary Tree
- LeetCode——Minimum Depth of Binary Tree
- LeetCode——Minimum Depth of Binary Tree
- leetcode 111 —— Minimum Depth of Binary Tree
- LeetCode——111. Minimum Depth of Binary Tree
- LeetCode——111. Minimum Depth of Binary Tree
- jquery extend 解析
- hadoop 2.7.3 单机模式
- JavaScript学习笔记20-while循环
- gitHub使用入门和github for windows的安装教程
- 百度地图定位
- LeetCode刷题(C++)——Minimum Depth if Binary Tree(Easy)
- LeetCode: Intersection of Two Linked Lists
- 欢迎使用CSDN-markdown编辑器
- 将bmp图像转换为ppm格式
- web项目部署补丁包
- MySQL各种时间取数函数
- python源码剖析笔记(二)
- ReactiveCocoa 基本使用回忆录
- 玩转ng-options小伎俩(转载+学习整理)