Leetcode Submission Details

来源:互联网 发布:linux kill -9怎么用 编辑:程序博客网 时间:2024/05/22 08:05

题意:找树最浅的深度。

思路: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;    }};


0 0
原创粉丝点击