(String s1, String s2)
| 1 | public class Solution { |
| 2 | public boolean checkInclusion(String s1, String s2) { |
| 3 | int n = s1.length(); |
| 4 | int[] freq = new int[26]; |
| 5 | int m = s2.length(); |
| 6 | for (int i = 0; i < n; i++) { |
| 7 | freq[s1.charAt(i) - 'a']++; |
| 8 | } |
| 9 | int[] freq2 = new int[26]; |
| 10 | for (int i = 0; i < m; i++) { |
| 11 | freq2[s2.charAt(i) - 'a']++; |
| 12 | if (i >= n) { |
| 13 | freq2[s2.charAt(i - n) - 'a']--; |
| 14 | } |
| 15 | if (Arrays.equals(freq, freq2)) |
| 16 | return true; |
| 17 | } |
| 18 | return false; |
| 19 | } |
| 20 | } |