微软面试一百道题目精选.docxVIP

  • 3
  • 0
  • 约6.21万字
  • 约 67页
  • 2018-08-15 发布于湖北
  • 举报
微软面试一百道题目精选

第9 题 判断整数序列是不是二元查找树的后序遍历结果 题目:输入一个整数数组,判断该数组是不是某二元查找树的后序遍历的结果。 如果是返回true,否则返回false。 例如输入5、7、6、9、11、10、8,由于这一整数序列是如下树的后序遍历结果: 8 / \ 6 10 / \ / \ 5 7 9 11 因此返回true。 如果输入7、4、6、5,没有哪棵树的后序遍历的结果是这个序列,因此返回false。 ANSWER: This is an interesting one. There is a traditional question that requires the binary tree to be re-constructed from mid/post/pre order results. This seems similar. For the problems related to (binary) trees, recursion is the first choice.? In this problem, we know in post-order results, the last number should be the root. So we have known the root of the BST is 8 in the example. So we

文档评论(0)

1亿VIP精品文档

相关文档