今際の国の呵呵君
Thursday, November 30, 2017
[LeetCode]Inorder Successor in BST
找后继结点,递归的思路,如果当前节点的值小于等于给定节点,去右子树找。否则,当前节点curr有可能是答案,那么我们需要去左子树找,如果能找到,我们return在左子树找到的值,因为其值比curr小,否则我们return curr的值。时间复杂度O(log n),代码如下:
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment