Concise Java Solution


  • 0
    public class Solution {
        public boolean checkInclusion(String s1, String s2) {
            int[] count = new int[26];
            for (char c : s1.toCharArray()) {
                count[c - 'a']++;
            }
            int left = 0;
            for (int i = 0; i < s2.length(); i++) {
                char c = s2.charAt(i);
                count[c - 'a']--;
                while (count[c - 'a'] < 0) {
                    count[s2.charAt(left++) - 'a']++;
                }
                if (i - left + 1 == s1.length()) return true;
            }
            return false;
        }
    }
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.