Leetcode#111 Minimum Depth of Binary Tree

原题地址

 

基本二叉树遍历

 

代码:

1 int minDepth(TreeNode *root) {
2         if (!root)
3             return 0;
4             
5         int l = root->left ? minDepth(root->left) : 0;
6         int r = root->right ? minDepth(root->right) : 0;
7         
8         return l * r > 0 ? min(l, r) + 1 : max(l, r) + 1;
9 }

 

posted @ 2015-02-02 11:47  李舜阳  阅读(96)  评论(0编辑  收藏  举报