PBO 59.99 AR# Hardware - 计算机硬件
h*0
1 楼
前面看到有一个贴子是判断isBinaryTree的问题
http://www.mitbbs.com/article_t/JobHunting/31521831.html
讨论结果主要有两个方向
(1) inOrderScan, 看看是不是结果排序了
(2) 对每一个节点判断是不是
node->val >= minValue(right tree)
node->val < maxValue(left tree)
对于第一种思路,我有一个问题,如果BST有重复值
BST assumes
left child <= current node < right child
但是如果我们只是看结果是不是排序,这个“=”就不知道在什么地方了
有可能是 for some node: left child < current node <=right child.
那即使结果是排序的,其实也是有问题。
我自己想可以用一些方法来检查,但是都很ugly. 所以不知道有没有什么更好的想法。
对于第二种思路,在上一个贴子里有提供一个链接
http://cslibrary.stanford
http://www.mitbbs.com/article_t/JobHunting/31521831.html
讨论结果主要有两个方向
(1) inOrderScan, 看看是不是结果排序了
(2) 对每一个节点判断是不是
node->val >= minValue(right tree)
node->val < maxValue(left tree)
对于第一种思路,我有一个问题,如果BST有重复值
BST assumes
left child <= current node < right child
但是如果我们只是看结果是不是排序,这个“=”就不知道在什么地方了
有可能是 for some node: left child < current node <=right child.
那即使结果是排序的,其实也是有问题。
我自己想可以用一些方法来检查,但是都很ugly. 所以不知道有没有什么更好的想法。
对于第二种思路,在上一个贴子里有提供一个链接
http://cslibrary.stanford