mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
19 lines
288 B
Python
19 lines
288 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
# author: bt3gl
|
|
|
|
|
|
def find_successor(root, p):
|
|
|
|
successor = None
|
|
|
|
while root:
|
|
|
|
if root.val <= p.val:
|
|
root = root.right
|
|
else:
|
|
successor = root
|
|
root = root.left
|
|
|
|
return successor
|