MCPcopy Index your code
hub / github.com/neetcode-gh/leetcode / checkInclusion

Method checkInclusion

java/0567-permutation-in-string.java:2–19  ·  view source on GitHub ↗
(String s1, String s2)

Source from the content-addressed store, hash-verified

1public 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}

Callers

nothing calls this directly

Calls 1

equalsMethod · 0.80

Tested by

no test coverage detected