当前位置:网站首页>Leetcode minimum absolute difference of binary search tree simple
Leetcode minimum absolute difference of binary search tree simple
2022-06-13 05:49:00 【AnWenRen】
title :530 The minimum absolute difference of binary search tree - Simple
subject
Give you a binary search tree root node
root, return The minimum difference between the values of any two different nodes in the tree .The difference is a positive number , Its value is equal to the absolute value of the difference between the two values .
Example 1
Input :root = [4,2,6,1,3]
Output :1
Example 2
Input :root = [1,0,48,null,null,12,49]
Output :1
Tips
- The number of nodes in the tree ranges from
[2, 104] 0 <= Node.val <= 105
Code Java
int pre;
int ans;
public int getMinimumDifference(TreeNode root) {
pre = -1;
ans = Integer.MAX_VALUE;
inOrder(root);
return ans;
}
// Middle order traversal to obtain the minimum value
public void inOrder(TreeNode root) {
if (root == null) return;
inOrder(root.left);
if (pre == -1)
pre = root.val;
else {
ans = Math.min(ans, root.val - pre);
pre = root.val;
}
inOrder(root.right);
}
边栏推荐
- Error: unmapped character encoding GBK
- 若依框架=》如何设置导入导出模板全局为文本格式(解决科学计数问题)
- The 13th week of the second semester of sophomore year
- 15 inclusivegateway and eventgateway of flowable gateway
- Leetcode- intersection of two arrays ii- simple
- 2020 personal annual summary
- 890. Find and Replace Pattern
- Interrupt processing
- Unity game optimization (version 2) learning record 7
- Config server configuration center of Nacos series
猜你喜欢

SPI primary key generation strategy for shardingsphere JDBC

Validation set: ‘flowable-executable-process‘ | Problem: ‘flowable-servicetask-missing-implementatio

Shardingsphere JDBC < bind table > avoid join Cartesian product

MySQL fuzzy query and sorting by matching degree

Solutions to conflicts between xampp and VMware port 443

Automatic database backup (using Navicat)

软件测试——接口常见问题汇总

OpenGL Mosaic (8)

Ffmpeg download suffix is Video files for m3u8

How MySQL optimizes the use of joint index ABC
随机推荐
Concurrent programming -- source code analysis of thread pool
JS output uincode code
Byte buddy print execution time and method link tracking
Mobile end adaptation scheme
20 flowable container (event sub process, things, sub process, pool and pool)
Integration of sentinel series Nacos to realize rule synchronization and persistence
15 inclusivegateway and eventgateway of flowable gateway
Difference between deviation and variance in deep learning
13 cancelendevent of a flowable end event and compensationthrowing of a compensation event
Current limiting and fusing of gateway gateway in Spirng cloud
Leetcode- reverse string - simple
Tongweb card, tongweb card, tongweb card
Config server configuration center of Nacos series
MongoDB 多字段聚合Group by
Sentinel series integrates Nacos and realizes dynamic flow control
2021.9.30学习日志-postman
Shardingsphere JDBC exception: no table route info
Find out the missing numbers from the natural numbers arranged in order from 0 to 100, and the solution provides
High availability of Nacos series
How to Algorithm Evaluation Methods