diff --git a/java/0567-permutation-in-string.java b/java/0567-permutation-in-string.java index 60c8e302a..ac24760c9 100644 --- a/java/0567-permutation-in-string.java +++ b/java/0567-permutation-in-string.java @@ -1,20 +1,59 @@ -public class Solution { +class Solution { + public boolean checkInclusion(String s1, String s2) { + int n = s1.length(); - int[] freq = new int[26]; int m = s2.length(); - for (int i = 0; i < n; i++) { - freq[s1.charAt(i) - 'a']++; - } - int[] freq2 = new int[26]; - for (int i = 0; i < m; i++) { - freq2[s2.charAt(i) - 'a']++; - if (i >= n) { - freq2[s2.charAt(i - n) - 'a']--; - } - if (Arrays.equals(freq, freq2)) + + if(n > m) + return false; + + int[] f1 = new int[26]; + int[] f2 = new int[26]; + + for(int i=0; i