leetcode答案-leetcode-:leetcode-

时间:2021-06-30 00:54:02
【文件属性】:
文件名称:leetcode答案-leetcode-:leetcode-
文件大小:728B
文件格式:ZIP
更新时间:2021-06-30 00:54:02
系统开源 leetcode 答案 leetcode- 参考答案 二叉树最小深度 思路 就左右两边找然后递归。 开始没有考虑到无根情况,导致一直是段错误 code class Solution { public: int run(TreeNode *root) { if(!root) return 0; if (root->left==NULL && root->right==NULL){ return 1; } else { int a=0; int b=0; if(root->left!=NULL) a=run(root->left); if(root->right!=NULL) b=run(root->right); if(a==0) return b+1; if(b==0) return a+1; return (a<b)?(a+1):(b+1); } } };
【文件预览】:
leetcode--master
----README.md(669B)

网友评论