@@ -0,0 +1,1844 @@
+package string.sliding_window;%0A%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0A%0Apublic class Q567PermutationInString %7B%0A%0A    //Difficulty: Medium%0A    //TAG: Facebook%0A    //TAG: String%0A    //TAG: Sliding window%0A%0A    /**%0A     * 567. Permutation in String%0A     * Given two strings s1 and s2, write a function to return true if s2 contains the permutation of s1. In other words, one of the first string's permutations is the substring of the second string.%0A     *%0A     *%0A     *%0A     * Example 1:%0A     *%0A     * Input: s1 = %22ab%22 s2 = %22eidbaooo%22%0A     * Output: True%0A     * Explanation: s2 contains one permutation of s1 (%22ba%22).%0A     * Example 2:%0A     *%0A     * Input:s1= %22ab%22 s2 = %22eidboaoo%22%0A     * Output: False%0A     *%0A     *%0A     * Note:%0A     *%0A     * The input strings only contain lower case letters.%0A     * The length of both given strings is in range %5B1, 10,000%5D.%0A     */%0A%0A    /*%0A    Solution:%0A%0A    sliding window%0A%0A    Time: O(m + n)%0A    Space: O(m)%0A     */%0A%0A    public boolean checkInclusion(String s1, String s2) %7B%0A        int len1 = s1.length(), len2 = s2.length();%0A        Map%3CCharacter, Integer%3E map = new HashMap%3C%3E();%0A        for (int i = 0; i %3C len1; i++) %7B%0A            char c = s1.charAt(i);%0A            map.put(c, map.getOrDefault(c, 0) + 1);%0A        %7D%0A        int count = 0;%0A        for (int i = 0; i %3C len2; i++) %7B%0A            char c = s2.charAt(i);%0A            if (map.containsKey(c)) %7B%0A                map.put(c, map.get(c) - 1);%0A                if (map.get(c) == 0) count++;%0A            %7D%0A            if (i %3E= len1) %7B%0A                char c2 = s2.charAt(i - len1);%0A                if (map.containsKey(c2)) %7B%0A                    map.put(c2, map.get(c2) + 1);%0A                    if (map.get(c2) == 1) count--;%0A                %7D%0A            %7D%0A            if (count == map.size()) return true;%0A        %7D%0A        return false;%0A    %7D%0A%0A%7D%0A

567. Permutation in String