题意:找树最浅的深度。
思路:DFS。
class Solution {
public:
int minDepth(TreeNode* root) {
if(root == NULL) return 0;
if(root->left == NULL && root->right == NULL) return 1;
int deepleft = 999999;
int deepright = 999999;
if(root->left) deepleft = minDepth(root->left) + 1;
if(root->right) deepright = minDepth(root->right) + 1;
return deepright>deepleft?deepleft:deepright;
}
};