Skip to content

[pull] master from youngyangyang04:master #235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 1, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions problems/0530.二叉搜索树的最小绝对差.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,27 @@ class Solution:
for i in range(len(res)-1): // 统计有序数组的最小差值
r = min(abs(res[i]-res[i+1]),r)
return r


class Solution: # 双指针法,不用数组 (同Carl写法) - 更快
def getMinimumDifference(self, root: Optional[TreeNode]) -> int:
global pre,minval
pre = None
minval = 10**5
self.traversal(root)
return minval

def traversal(self,root):
global pre,minval
if not root: return None
self.traversal(root.left)
if pre and root.val-pre.val<minval:
minval = root.val-pre.val
pre = root
self.traversal(root.right)
```


迭代法-中序遍历
```python
class Solution:
Expand Down