From 5f0b461ef92aafbf35a3c83397514f091bc84f85 Mon Sep 17 00:00:00 2001 From: Gaurav Kumar Date: Sun, 16 Jun 2024 08:05:33 +0530 Subject: [PATCH] Update 0567-permutation-in-string.java --- java/0567-permutation-in-string.java | 65 ++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 13 deletions(-) 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