-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPermutation in String
More file actions
39 lines (27 loc) · 844 Bytes
/
Copy pathPermutation in String
File metadata and controls
39 lines (27 loc) · 844 Bytes
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
LEETCODE PROBLEM SOLVING
PROBLEM->PERMUTATION IN STRING
class Solution {
public boolean checkInclusion(String s1, String s2) {
if (s1.length() > s2.length()) {
return false;
}
int[] count1 = new int[26];
int[] count2 = new int[26];
for (char c : s1.toCharArray()) {
count1[c - 'a']++;
}
int left = 0;
for (int right = 0; right < s2.length(); right++) {
count2[s2.charAt(right) - 'a']++;
if (right - left + 1 > s1.length()) {
count2[s2.charAt(left) - 'a']--;
left++;
}
if (Arrays.equals(count1, count2)) {
return true;
}
}
return false;
}
}TRTRFTFFFFFFFFFFEWQWSWAQ `123456DXSCVGHyujh^DSFGTFRDERTGFRDSWEFGVNM ,
{