https://www.cnblogs.com/robsann/p/7567596.html
https://blog.csdn.net/qq_33243189/article/details/80222629
两篇讲解二叉树比较好的文章
二叉树的中序遍历--python3
783. Minimum Distance Between BST Nodes
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
def minDiffInBST(self, root):
"""
:type root: TreeNode
:rtype: int
"""
res = []
def res_list(root):
if root == None:
return []
res_list(root.left)
res.append(root.val)
res_list(root.right)
res_list(root) #中序遍历函数
result1 = []
for i in range(len(res) - 1):
result1.append(res[i+1] - res[i])
print(result1)
return min(result1)