Golang solution


  • 0
    func checkInclusion(s1 string, s2 string) bool {
        n1,n2:=len(s1),len(s2)
        f1 := make([]int,26);
        for _,v := range s1 {
            f1[v-'a']++;
        }
        f2 := make([]int,26);
        for j:=0;j<n2;j++ {
            f2[s2[j]-'a']++;
            if j>=n1 {
                f2[s2[j-n1]-'a']--;
            }
            if reflect.DeepEqual(f2, f1) {
              return true;  
            } 
        }
    	return false
    }
    

Log in to reply
 

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