Skip to content

Commit b9f7d89

Browse files
committed
fd
1 parent 86ad19e commit b9f7d89

File tree

3 files changed

+2
-21
lines changed

3 files changed

+2
-21
lines changed

solution/src/main/java/com/inuker/solution/ClosestBinarySearchTreeValueII.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
/**
1515
* 有三种解法:
16-
* 1,中序完整遍历一遍二叉树形成一个list,再找到最接近target的node,然后依次往左右两边延伸到找满k个节点,复杂度O(n + lgn + k)
1716
* 2,中序遍历两遍二叉树,不过每次都会中途退出,构成双栈,一个是大于target,一个是小于target,然后依次出栈满k为止,复杂度O(n + k)
1817
* 3,中序完整遍历一遍二叉树,依次将节点加入优先级队列,按与target的差排序,选前k个,复杂度O(nlgk)
1918
*/

solution/src/main/java/com/inuker/solution/InorderSuccessorInBST.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
public class InorderSuccessorInBST {
1818

1919
// 耗时10ms
20+
// 时间复杂度O(n)
2021
public TreeNode inorderSuccessor(TreeNode root, TreeNode p) {
2122
Stack<TreeNode> stack = new Stack<TreeNode>();
2223
TreeNode node = null, prev = null;
Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.inuker.test;
22

3+
import com.leetcode.library.Interval;
34
import com.leetcode.library.TreeNode;
45

56
import java.util.ArrayList;
@@ -21,26 +22,6 @@
2122
public class main {
2223

2324
public static void main(String[] args) {
24-
}
2525

26-
public int[] maxSlidingWindow(int[] nums, int k) {
27-
if (nums.length == 0 || k == 0) {
28-
return new int[0];
29-
}
30-
int[] result = new int[nums.length - k + 1];
31-
Deque<Integer> queue = new LinkedList<>();
32-
for (int i = 0; i < nums.length; i++) {
33-
while (!queue.isEmpty() && nums[i] > nums[queue.peekLast()]) {
34-
queue.pollLast();
35-
}
36-
queue.offerLast(i);
37-
if (queue.peekFirst() + k <= i) {
38-
queue.pollFirst();
39-
}
40-
if (i - k + 1 >= 0) {
41-
result[i - k + 1] = nums[queue.peekFirst()];
42-
}
43-
}
44-
return result;
4526
}
4627
}

0 commit comments

Comments
 (0)