```
class Solution(object):
def inorderSuccessor(self, root, p):
"""
:type root: TreeNode
:type p: TreeNode
:rtype: TreeNode
"""
foundP = False
for i in self.inorder(root):
if i == p:
foundP = True
continue
if foundP:
return i
return None
def inorder(self, node):
if node.left:
for ele in self.inorder(node.left):
yield ele
yield node
if node.right:
for ele in self.inorder(node.right):
yield ele
```