Easy
,Tree
,BFS
,DFS
,Binary Tree
783. Minimum Distance Between BST Nodes
Given the root
of a Binary Search Tree (BST), return the minimum difference between the values of any two different nodes in the tree.
Example 1:
Example 2:
Constraints:
[2, 100]
.Note: This question is the same as 530: https://leetcode.com/problems/minimum-absolute-difference-in-bst/
我超笨,本來做DFS取整棵樹的值,排序後依序相減,找到差最小的,完全忘記他是BST,可以直接用Inorder Traversal,這樣就是排序好的值了。
MarsgoatFeb 17, 2023
樓上做法的 Recursive 版
Ron ChenFri, Feb 17, 2023
畢竟大家都是學對局的,來點AlphaBeta不過分吧?
Yen-Chi ChenFri, Feb 17, 2023