Skip to content

Commit af7dc60

Browse files
edit 239
1 parent 2930d48 commit af7dc60

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ Your ideas/fixes/algorithms are more than welcome!
306306
|242|[Valid Anagram](https://leetcode.com/problems/valid-anagram/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_242.java) | O(n) | O(1) | Easy
307307
|241|[Different Ways to Add Parentheses](https://leetcode.com/problems/different-ways-to-add-parentheses/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_241.java) | O(O(n * 4^n / n^(3/2))) | O(n * 4^n / n^(3/2)) | Medium | Divide and Conquer
308308
|240|[Search a 2D Matrix II](https://leetcode.com/problems/search-a-2d-matrix-ii/)|[Solution](../master/src/main/java/com/fishercoder/solutions/Searcha2DMatrixII.java)| O(log(m*n))|O(1) | Medium| Binary Search
309-
|239|[Sliding Window Maximum](https://leetcode.com/problems/sliding-window-maximum/)|[Solution](../master/src/main/java/com/fishercoder/solutions/SlidingWindowMaximum.java)| O(nlogn)|O(k) | Hard| Heap
309+
|239|[Sliding Window Maximum](https://leetcode.com/problems/sliding-window-maximum/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_239.java)| O(nlogn)|O(k) | Hard| Heap
310310
|238|[Product of Array Except Self](https://leetcode.com/problems/product-of-array-except-self/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_238.java)| O(n)|O(1) | Medium| Array
311311
|237|[Delete Node in a Linked List](https://leetcode.com/problems/delete-node-in-a-linked-list/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_237.java)| O(1)|O(1) | Easy| LinkedList
312312
|236|[Lowest Common Ancestor of a Binary Tree](https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-tree/)|[Solution](../master/src/main/java/com/fishercoder/solutions/_236.java)| O(n)|O(h) | Medium| DFS

src/main/java/com/fishercoder/solutions/SlidingWindowMaximum.java src/main/java/com/fishercoder/solutions/_239.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import java.util.*;
44

55
/**
6-
* Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.
6+
* Given an array nums, there is a sliding window of size k which is moving from the very left of the array to the very right.
7+
* You can only see the k numbers in the window. Each time the sliding window moves right by one position.
78
89
For example,
910
Given nums = [1,3,-1,-3,5,3,6,7], and k = 3.
@@ -30,19 +31,17 @@ How about using a data structure such as deque (double-ended queue)?
3031
The queue size need not be the same as the window’s size.
3132
Remove redundant elements and the queue should store only elements that need to be considered.
3233
*/
33-
public class SlidingWindowMaximum {
34+
public class _239 {
3435

3536
public int[] maxSlidingWindow(int[] nums, int k) {
3637
if(nums == null || nums.length == 0 || k == 0) return new int[0];
3738
Queue<Integer> heap = new PriorityQueue<Integer>(new Comparator<Integer>(){
38-
3939
@Override
4040
public int compare(Integer o1, Integer o2) {
4141
if(o1 > o2) return -1;
4242
else if(o1 < o2) return 1;
4343
else return 0;
4444
}
45-
4645
}
4746
);
4847
int i = 0;

src/test/java/com/fishercoder/SlidingWindowMaximumTest.java src/test/java/com/fishercoder/_239Test.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.fishercoder;
22

3-
import com.fishercoder.solutions.SlidingWindowMaximum;
3+
import com.fishercoder.solutions._239;
44
import org.junit.Assert;
55
import org.junit.Before;
66
import org.junit.BeforeClass;
@@ -9,16 +9,16 @@
99
/**
1010
* Created by fishercoder on 1/10/17.
1111
*/
12-
public class SlidingWindowMaximumTest {
13-
private static SlidingWindowMaximum test;
12+
public class _239Test {
13+
private static _239 test;
1414
private static int[] expected;
1515
private static int[] actual;
1616
private static int[] nums;
1717
private static int k;
1818

1919
@BeforeClass
2020
public static void setup(){
21-
test = new SlidingWindowMaximum();
21+
test = new _239();
2222
}
2323

2424
@Before

0 commit comments

Comments
 (0)