530.二叉搜索树的最小绝对差 python迭代法没有取abs

This commit is contained in:
大林程序员 2022-09-04 17:39:00 +08:00 committed by GitHub
parent c59b354990
commit ef0cb55638
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 1 additions and 1 deletions

View File

@ -233,7 +233,7 @@ class Solution:
else: # 逐一处理节点
cur = stack.pop()
if pre: # 当前节点和前节点的值的差值
result = min(result, cur.val - pre.val)
result = min(result, abs(cur.val - pre.val))
pre = cur
cur = cur.right
return result