Leetcode-567 Permutation in String(字符串的排列)

 1 class Solution
 2 {
 3     public:
 4         bool checkInclusion(string s1, string s2)
 5         {
 6             if(s2.size()<s1.size())
 7                 return false;
 8             int length = s1.size();
 9             int hashForA[29] {0};
10             bool result = false;
11             
12             for(int i = 0;i < length;i ++)
13             {
14                 hashForA[s1[i]-'a'] ++;
15             }
16             for(int i = 0;i < s2.size()-length+1;i ++)
17             {
18                 int hash[29] {0};
19                 for(int j = 0;j < length;j ++)
20                 {
21                     hash[s2[i+j]-'a'] ++;
22                 }
23                 int k;
24                 for(k = 0;k < 28;k ++)
25                 {
26                     if(hash[k] != hashForA[k])
27                         break;
28                 }
29                 if(k == 28)
30                     result = true;
31             }
32             return result;
33         }
34 };

 

posted @ 2018-09-20 11:07  Asurudo  阅读(176)  评论(0编辑  收藏  举报