首页 > 代码库 > Leetcode#111 Minimum Depth of Binary Tree

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 }

 

Leetcode#111 Minimum Depth of Binary Tree