File tree Expand file tree Collapse file tree 5 files changed +90
-6
lines changed
LeetCodeSolutions/HardLevelSolutions
src/main/java/com/javaaid/solutions/hard Expand file tree Collapse file tree 5 files changed +90
-6
lines changed Original file line number Diff line number Diff line change 12
12
<attribute name =" maven.pomderived" value =" true" />
13
13
</attributes >
14
14
</classpathentry >
15
- <classpathentry kind =" con" path =" org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE -1.5 " >
15
+ <classpathentry kind =" con" path =" org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE -1.8 " >
16
16
<attributes >
17
17
<attribute name =" maven.pomderived" value =" true" />
18
18
</attributes >
Original file line number Diff line number Diff line change 1
1
eclipse.preferences.version =1
2
2
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode =enabled
3
- org.eclipse.jdt.core.compiler.codegen.targetPlatform =1.5
4
- org.eclipse.jdt.core.compiler.compliance =1.5
3
+ org.eclipse.jdt.core.compiler.codegen.targetPlatform =1.8
4
+ org.eclipse.jdt.core.compiler.compliance =1.8
5
5
org.eclipse.jdt.core.compiler.problem.assertIdentifier =error
6
6
org.eclipse.jdt.core.compiler.problem.enumIdentifier =error
7
7
org.eclipse.jdt.core.compiler.problem.forbiddenReference =warning
8
- org.eclipse.jdt.core.compiler.source =1.5
8
+ org.eclipse.jdt.core.compiler.source =1.8
Original file line number Diff line number Diff line change 7
7
<artifactId >LeetCodeSolutions</artifactId >
8
8
<version >0.0.1-SNAPSHOT</version >
9
9
</parent >
10
- <groupId >com.javaaid.leetcode</groupId >
11
10
<artifactId >HardLevelSolutions</artifactId >
12
- <version >0.0.1-SNAPSHOT</version >
13
11
<name >HardLevelSolutions</name >
14
12
<url >http://maven.apache.org</url >
15
13
<properties >
Original file line number Diff line number Diff line change
1
+ /**
2
+ *
3
+ */
4
+ package com .javaaid .solutions .hard .heaps ;
5
+
6
+ import java .util .ArrayDeque ;
7
+ import java .util .Arrays ;
8
+ import java .util .Deque ;
9
+
10
+ /**
11
+ * @author Kanahaiya Gupta
12
+ *
13
+ */
14
+ public class SlidingWindowMaximum {
15
+
16
+ public static int [] maxSlidingWindow (int [] nums , int k ) {
17
+ if (nums .length == 0 || nums == null || k == 0 )
18
+ return new int [0 ];
19
+
20
+ int result [] = new int [nums .length - k + 1 ];
21
+ Deque <Integer > window = new ArrayDeque <Integer >();
22
+ int m = 0 ;
23
+ for (int i = 0 ; i < nums .length ; i ++) {
24
+ while (!window .isEmpty () && nums [window .peekLast ()] < nums [i ]) {
25
+ window .pollLast ();
26
+ }
27
+ while (!window .isEmpty () && window .peek () < i - k + 1 ) {
28
+ window .poll ();
29
+ }
30
+ window .offer (i );
31
+ if (i >= k - 1 ) {
32
+ result [m ++] = nums [window .peek ()];
33
+ }
34
+ }
35
+ return result ;
36
+ }
37
+ }
Original file line number Diff line number Diff line change
1
+ /**
2
+ *
3
+ */
4
+ package com .javaaid .solutions .hard .twopointer ;
5
+
6
+ import java .util .HashMap ;
7
+
8
+ /**
9
+ * @author Kanahaiya Gupta
10
+ *
11
+ */
12
+ public class MinimumWindowSubstring {
13
+
14
+ public String minWindow (String s , String t ) {
15
+ HashMap <Character , Integer > hmap = new HashMap <Character , Integer >();
16
+
17
+ for (char ch : t .toCharArray ()) {
18
+ hmap .put (ch , hmap .getOrDefault (ch , 0 ) + 1 );
19
+ }
20
+ int counter = hmap .size ();
21
+ int begin = 0 , end = 0 , len = Integer .MAX_VALUE ;
22
+ String ans = "" ;
23
+ while (end < s .length ()) {
24
+ char endChar = s .charAt (end );
25
+ Integer count = hmap .get (endChar );
26
+ if (count != null ) {
27
+ hmap .put (endChar , count - 1 );
28
+ if (hmap .get (endChar ) == 0 )
29
+ counter --;
30
+ }
31
+ end ++;
32
+
33
+ while (counter == 0 ) {
34
+ char c = s .charAt (begin );
35
+ if (hmap .get (c ) != null ) {
36
+ hmap .put (c , hmap .get (c ) + 1 );
37
+ if (hmap .get (c ) > 0 )
38
+ counter ++;
39
+ }
40
+ if (end - begin < len ) {
41
+ len = end - begin ;
42
+ ans = s .substring (begin , begin + len );
43
+ }
44
+ begin ++;
45
+ }
46
+ }
47
+ return ans ;
48
+ }
49
+ }
You can’t perform that action at this time.
0 commit comments