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

Sign up
Appearance settings

Commit 53c96db

Browse files
Update package name
1 parent 6cd02bb commit 53c96db

File tree

3 files changed

+98
-1
lines changed

3 files changed

+98
-1
lines changed

LeetCodeSolutions/HardLevelSolutions/src/main/java/com/javaaid/solutions/hard/twopointer/MinimumWindowSubstring.java renamed to LeetCodeSolutions/HardLevelSolutions/src/main/java/com/javaaid/solutions/hard/twopointers/MinimumWindowSubstring.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
*
33
*/
4-
package com.javaaid.solutions.hard.twopointer;
4+
package com.javaaid.solutions.hard.twopointers;
55

66
import java.util.HashMap;
77

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/**
2+
*
3+
*/
4+
package com.javaaid.solutions.medium.twopointers;
5+
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
9+
/**
10+
* @author Kanahaiya Gupta
11+
*
12+
*/
13+
public class LongestSubstringWithoutRepeatingCharacters {
14+
15+
public static void main(String[] args) {
16+
int result = lengthOfLongestSubstring("abcabcbb");
17+
System.out.println(result);
18+
}
19+
20+
public static int lengthOfLongestSubstring(String s) {
21+
if(s==null||s==""||s.isEmpty())return 0;
22+
Map<Character, Integer> map = new HashMap<Character, Integer>();
23+
int begin = 0, end = 0, len = Integer.MIN_VALUE;
24+
Integer index = 0;
25+
while (end < s.length()) {
26+
char endChar = s.charAt(end);
27+
index = map.get(endChar);
28+
if (index != null && index >= begin) {
29+
begin++;
30+
31+
} else {
32+
map.put(endChar, end);
33+
end++;
34+
35+
}
36+
37+
if (end - begin > len) {
38+
len = end - begin;
39+
}
40+
}
41+
return len==Integer.MIN_VALUE?0:len;
42+
}
43+
44+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
*
3+
*/
4+
package com.javaaid.solutions.medium.twopointers;
5+
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
9+
/**
10+
* @author Kanahaiya Gupta
11+
*
12+
*/
13+
public class PermutationInString {
14+
15+
16+
public static boolean checkInclusion(String s1, String s2) {
17+
Map<Character, Integer> map = new HashMap<Character, Integer>();
18+
19+
for (char ch : s1.toCharArray()) {
20+
map.put(ch, map.getOrDefault(ch, 0) + 1);
21+
}
22+
23+
int begin = 0, end = 0, len = s1.length();
24+
Integer count = 0;
25+
int counter = map.size();
26+
while (end < s2.length()) {
27+
char endChar = s2.charAt(end);
28+
count = map.get(endChar);
29+
if (count != null) {
30+
map.put(endChar, count - 1);
31+
if (map.get(endChar) == 0)
32+
counter--;
33+
}
34+
end++;
35+
while (counter == 0) {
36+
char startChar = s2.charAt(begin);
37+
count = map.get(startChar);
38+
if (count != null) {
39+
map.put(startChar, count + 1);
40+
if (map.get(startChar) > 0)
41+
counter++;
42+
}
43+
if (len == end - begin) {
44+
return true;
45+
}
46+
begin++;
47+
}
48+
49+
}
50+
return false;
51+
52+
}
53+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /