-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
面试题7:重建二叉树 #56
Comments
只有一个节点且这个节点还和记录的根节点rootValue不一致,就是非法输入的意思吧 |
判断前序遍历找到的根的值 跟中序遍历里的根的值 是否相等吧 |
首先,这两句是在第61和62行。 |
赞同!0.0 刚看到书的这块,觉得有点小问题。 |
刚才看到这块也觉得有问题,61行改成 |
虽然这个地方跑代码没有问题的,如果rootInorder > endInorder。那么在构建右子树的时候就会抛出异常。但是这个地方应该是写错了,不然太奇怪了。 |
66-67行代码
if(rootInorder == endInorder && *rootInorder != rootValue)
throw std::exception("Invalid input.");
这句没有用吧!
The text was updated successfully, but these errors were encountered: