-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMapp.java
88 lines (68 loc) · 2.41 KB
/
Mapp.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import java.util.Arrays;
class Mapp {
public boolean checkInclusion(String s1, String s2) {
String x = s1;
String y = s2;
if (x.length() > y.length()) {
return false;
}
int[] xFreq = new int[26];
int[] windowFreq = new int[26];
for (int i = 0; i < x.length(); i++) {
xFreq[x.charAt(i) - 'a']++;
windowFreq[y.charAt(i) - 'a']++;
}
for (int i = 0; i <= y.length() - x.length(); i++) {
if (Arrays.equals(xFreq, windowFreq)) {
return true;
}
if (i + x.length() < y.length()) {
windowFreq[y.charAt(i) - 'a']--;
windowFreq[y.charAt(i + x.length()) - 'a']++;
}
}
return Arrays.equals(xFreq, windowFreq);
}
public static void main(String[] args) {
Mapp mapp = new Mapp();
System.out.println(mapp.checkInclusion("ab", "eidbaooo")); // true
System.out.println(mapp.checkInclusion("ab", "eidboaoo")); // false
int a = 3, b = 4;
// System.out.println(a || b);
for (int i = 0; (i < a) || (i < b); i++) {
String s = "hello hey";
String[] arg = s.split(" ");
System.out.println(arg[1]);
}
// char ab = 'a';
// char ba = 'b';
// System.out.println(ab + ba);
// String s = "Hello the";
// StringBuilder sb = new StringBuilder(s);
// System.out.println((sb.charAt(0) + sb.charAt(1)));
// StringBuilder stb = new StringBuilder();
char ch1 = 't';
char ch2 = 'c';
// String sts = stb.append(ch1).append(ch2).toString();
// System.out.println(sts.equals("tc"));
// StringBuilder sb = new StringBuilder("Hello World");
// int length = sb.length();
// System.out.println(sb);
// sb.delete(0, 1);
// System.out.println(sb);
// String sts = new String("AB");
String sts="AB";
if (sts == "AB" || sts == "CD") {
System.out.println("True");
} else {
System.out.println("False");
}
// StringBuilder stb = new StringBuilder();
// String sts = stb.append(ch1).append(ch2).toString();
// if (sts == "AB" || sts == "CD") {
// System.out.println("true");
// } else {
// System.out.println("Fal");
// }
}
}