Skip to main content

510 - Inorder Successor in BST II

Details

KeyValue
Linkhttps://leetcode.com/problems/word-abbreviation/
LanguagePython 3
Runtime142 ms, faster than 29.65% of Python3 online submissions for Inorder Successor in BST II
Memory Usage21.7 MB, less than 13.44% of Python3 online submissions for Inorder Successor in BST II
DatastructuresNode
AlgorithmsIteration
ComplexityTime: O(H) Memory: O(1) (H=Hieght of tree)

Procedure

  1. ...

Code

class Solution:
def inorderSuccessor(self, node: 'Node') -> 'Optional[Node]':
if node.right:
node = node.right
while node.left: node = node.left
return node

while node.parent and node.parent.val < node.val:
node = node.parent

return node.parent