Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 743227a

Browse filesBrowse files
committed
commit
Change-Id: Id41004d654d277ea27da6318cb54af6f85131431
1 parent bd64272 commit 743227a
Copy full SHA for 743227a

File tree

Expand file treeCollapse file tree

14 files changed

+263
-0
lines changed
Filter options
Expand file treeCollapse file tree

14 files changed

+263
-0
lines changed
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
<orderEntry type="module-library">
11+
<library name="JUnit4">
12+
<CLASSES>
13+
<root url="jar://$MODULE_DIR$/../lib/junit-4.12.jar!/" />
14+
<root url="jar://$MODULE_DIR$/../lib/hamcrest-core-1.3.jar!/" />
15+
</CLASSES>
16+
<JAVADOC />
17+
<SOURCES />
18+
</library>
19+
</orderEntry>
20+
</component>
21+
</module>
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package PACKAGE_NAME;
2+
3+
/**
4+
* Author: 王俊超
5+
* Time: 2020-06-30 10:06
6+
* CSDN: http://blog.csdn.net/derrantcm
7+
* Github: https://github.com/Wang-Jun-Chao
8+
* Declaration: All Rights Reserved !!!
9+
**/
10+
public class Solution {
11+
}
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import static org.junit.Assert.*;
2+
3+
/**
4+
* Author: 王俊超
5+
* Time: 2020-06-30 10:14
6+
* CSDN: http://blog.csdn.net/derrantcm
7+
* Github: https://github.com/Wang-Jun-Chao
8+
* Declaration: All Rights Reserved !!!
9+
**/
10+
public class SolutionTest {
11+
12+
}
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Author: 王俊超
3+
* Time: 2020-06-29 11:06
4+
* CSDN: http://blog.csdn.net/derrantcm
5+
* Github: https://github.com/Wang-Jun-Chao
6+
* Declaration: All Rights Reserved !!!
7+
**/
8+
public class TreeNode {
9+
int val;
10+
TreeNode left;
11+
TreeNode right;
12+
13+
TreeNode(int x) {
14+
val = x;
15+
}
16+
}
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package PACKAGE_NAME;
2+
3+
/**
4+
* Author: 王俊超
5+
* Time: 2020-06-30 12:50
6+
* CSDN: http://blog.csdn.net/derrantcm
7+
* Github: https://github.com/Wang-Jun-Chao
8+
* Declaration: All Rights Reserved !!!
9+
**/
10+
public class Solution {
11+
}
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import static org.junit.Assert.*;
2+
3+
/**
4+
* Author: 王俊超
5+
* Time: 2020-06-30 12:54
6+
* CSDN: http://blog.csdn.net/derrantcm
7+
* Github: https://github.com/Wang-Jun-Chao
8+
* Declaration: All Rights Reserved !!!
9+
**/
10+
public class SolutionTest {
11+
12+
}
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package PACKAGE_NAME;
2+
3+
/**
4+
* Author: 王俊超
5+
* Time: 2020-07-01 08:53
6+
* CSDN: http://blog.csdn.net/derrantcm
7+
* Github: https://github.com/Wang-Jun-Chao
8+
* Declaration: All Rights Reserved !!!
9+
**/
10+
public class Solution {
11+
}
+12Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import static org.junit.Assert.*;
2+
3+
/**
4+
* Author: 王俊超
5+
* Time: 2020-07-01 08:57
6+
* CSDN: http://blog.csdn.net/derrantcm
7+
* Github: https://github.com/Wang-Jun-Chao
8+
* Declaration: All Rights Reserved !!!
9+
**/
10+
public class SolutionTest {
11+
12+
}
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Author: 王俊超
3+
* Time: 2020-06-29 11:06
4+
* CSDN: http://blog.csdn.net/derrantcm
5+
* Github: https://github.com/Wang-Jun-Chao
6+
* Declaration: All Rights Reserved !!!
7+
**/
8+
public class TreeNode {
9+
int val;
10+
TreeNode left;
11+
TreeNode right;
12+
13+
TreeNode(int x) {
14+
val = x;
15+
}
16+
}
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
+92Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
import java.util.*;
2+
3+
/**
4+
* Author: 王俊超
5+
* Time: 2020-06-29 10:09
6+
* CSDN: http://blog.csdn.net/derrantcm
7+
* Github: https://github.com/Wang-Jun-Chao
8+
* Declaration: All Rights Reserved !!!
9+
**/
10+
public class Solution {
11+
/**
12+
* 解题思路
13+
* root提个二叉搜索树
14+
* 二叉查找树(Binary Search Tree),(又:二叉搜索树,二叉排序树)它或者是一棵空树,或者是具有下列性质的二叉树:
15+
* 若它的左子树不空,则左子树上所有结点的值均小于它的根结点的值;
16+
* 若它的右子树不空,则右子树上所有结点的值均大于它的根结点的值;
17+
* 它的左、右子树也分别为二叉排序树。
18+
*
19+
* @param root
20+
* @return
21+
*/
22+
public int getMinimumDifference(TreeNode root) {
23+
24+
if (root == null) {
25+
return 0;
26+
}
27+
Deque<TreeNode> s = new LinkedList<>();
28+
int min = Integer.MAX_VALUE;
29+
int prev = 0;
30+
boolean first = true;
31+
while (root != null || !s.isEmpty()) {
32+
while (root != null) {
33+
s.push(root);//先访问再入栈
34+
root = root.left;
35+
}
36+
root = s.pop();
37+
38+
if (first) {
39+
first = false;
40+
} else {
41+
min = Math.min(min, root.val - prev);
42+
}
43+
44+
prev = root.val;
45+
root = root.right;//如果是null,出栈并处理右子树
46+
}
47+
48+
return min;
49+
}
50+
51+
public int getMinimumDifference2(TreeNode root) {
52+
53+
if (root == null) {
54+
return 0;
55+
}
56+
57+
List<Integer> list = new ArrayList<>();
58+
59+
Deque<TreeNode> queue = new LinkedList<>();
60+
queue.add(root);
61+
while (!queue.isEmpty()) {
62+
TreeNode node = queue.poll();
63+
list.add(node.val);
64+
if (node.right != null) {
65+
queue.addFirst(node.right);
66+
}
67+
if (node.left != null) {
68+
queue.addFirst(node.left);
69+
}
70+
}
71+
72+
73+
if (list.size() == 1) {
74+
return list.get(0);
75+
}
76+
77+
list.sort(new Comparator<Integer>() {
78+
@Override
79+
public int compare(Integer o1, Integer o2) {
80+
return o1 - o2;
81+
}
82+
});
83+
84+
int min = Integer.MAX_VALUE;
85+
86+
for (int i = 1; i < list.size(); i++) {
87+
min = Math.min(min, Math.abs(list.get(i - 1) - list.get(i)));
88+
}
89+
90+
return min;
91+
}
92+
}
+16Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Author: 王俊超
3+
* Time: 2020-06-29 11:06
4+
* CSDN: http://blog.csdn.net/derrantcm
5+
* Github: https://github.com/Wang-Jun-Chao
6+
* Declaration: All Rights Reserved !!!
7+
**/
8+
public class TreeNode {
9+
int val;
10+
TreeNode left;
11+
TreeNode right;
12+
13+
TreeNode(int x) {
14+
val = x;
15+
}
16+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.