Skip to content

Commit

Permalink
783
Browse files Browse the repository at this point in the history
  • Loading branch information
ProHiryu committed May 22, 2020
1 parent 145b322 commit 0f0f271
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Tree/783.md
@@ -0,0 +1,42 @@
## Minimum Distance Between BST Nodes

#### Description

[link](https://leetcode.com/problems/n-ary-tree-postorder-traversal/)

---

#### Solution

- See Code

---

#### Code

> Complexity T : O(N) M : O(n)
```python
# 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: TreeNode) -> int:
stack = []
ans, pre = float("inf"), float("-inf")
while root or stack:
if root:
stack.append(root)
root = root.left
else:
root = stack.pop()
ans = min(ans, root.val - pre)
pre = root.val
root = root.right

return ans
```

0 comments on commit 0f0f271

Please sign in to comment.