Question
Given a binary search tree with non-negative values, find the minimum absolute difference between values of any two nodes.
Example:
Explanation: The minimum absolute difference is 1, which is the difference between 2 and 1 (or between 2 and 3). Note: There are at least two nodes in this BST
Explanation
按照之前Leetcode 94.Binary Tree Inorder Traversal的思路,可用递归来做。但是如果不是BST的话,我们也可以用Treeset来存值,同样用递归。 两种方法如下,第一种Time complexity O(N), space complexity O(1),第二种的话Time complexity O(NlgN), space complexity O(N).