【在 e******r 的大作中提到】 : thanks for sharing! : -Elsevier
b*u
7 楼
那样达不到O(1)吧
【在 p*****2 的大作中提到】 : traverse一遍就可以了吧?
e*r
8 楼
哈哈,我现在这个id用多了,在本版一看见,第一反应就是自作多情的以为点我名儿呢。
【在 f*******l 的大作中提到】 : Thanks! : 终于知道花瓣的出处了:)
p*2
9 楼
两个变量就可以了吧?
【在 b*****u 的大作中提到】 : 那样达不到O(1)吧
b*e
10 楼
very nice :)
【在 e******r 的大作中提到】 : thanks for sharing! : -Elsevier
e*e
11 楼
Assume there is only one value got duplicated. global variable: int count = 0; void inorderDFS(Node n, MutableInt prev) { if ( node == null ) return; inorderDFS( node.left, prev ); if ( n.val == prev.val ) count++; pre.val = node.val; inorderDFS( node.right, prev ); } invoke: inorderDFS( root, new MutableInt() ); return: count class MutableInt { int val; }
In computer science, a binary search tree (BST), which may sometimes also be called an ordered or sorted binary tree, is a node-based binary tree data structure which has the following properties:[1] The left subtree of a node contains only nodes with keys less than the node' s key. The right subtree of a node contains only nodes with keys greater than the node's key. Both the left and right subtrees must also be binary search trees. There must be no duplicate nodes.
【在 e****e 的大作中提到】 : by Interview Candidate: Oct 24, 2012 : yes you are correct, I meant a BST : : )
【在 l*****a 的大作中提到】 : In computer science, a binary search tree (BST), which may sometimes also be : called an ordered or sorted binary tree, is a node-based binary tree data : structure which has the following properties:[1] : The left subtree of a node contains only nodes with keys less than the node' : s key. : The right subtree of a node contains only nodes with keys greater than the : node's key. : Both the left and right subtrees must also be binary search trees. : There must be no duplicate nodes.