We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent c4f1640 commit a3531f9Copy full SHA for a3531f9
Medium/Permutation in String.java
@@ -0,0 +1,31 @@
1
+class Solution {
2
+ public boolean checkInclusion(String s1, String s2) {
3
+ int l1 = s1.length();
4
+ int l2 = s2.length();
5
+ if (l1 > l2) return false;
6
+
7
+ int[] check = new int[26];
8
9
+ for (int i=0;i<l1;i++) {
10
+ check[s1.charAt(i)-'a']++;
11
+ check[s2.charAt(i)-'a']--;
12
+ }
13
14
+ if (zeroArr(check)) return true;
15
16
+ for (int i = l1; i < l2; i++) {
17
+ check[s2.charAt(i) - 'a']--;
18
+ check[s2.charAt(i - l1) - 'a']++;
19
20
21
22
+ return false;
23
24
25
+ boolean zeroArr(int[] arr) {
26
+ for (int i=0;i<26;i++) {
27
+ if (arr[i] != 0) return false;
28
29
+ return true;
30
31
+}
0 commit comments