| 1 | //two map comparision |
| 2 | class Solution { |
| 3 | public boolean checkInclusion(String s1, String s2) { |
| 4 | int n = s1.length(); |
| 5 | int m = s2.length(); |
| 6 | if(m<n) return false; |
| 7 | int map1[] = new int[26]; //0 |
| 8 | |
| 9 | for(int i=0;i<n;i++){ |
| 10 | map1[s1.charAt(i) - 'a']++; |
| 11 | } |
| 12 | for(int i=0;i<=m-n;i++){ |
| 13 | int map2[] = new int[26]; |
| 14 | for(int j=0;j<n;j++){ |
| 15 | map2[s2.charAt(i+j) - 'a']++; |
| 16 | } |
| 17 | if(isMatched(map1,map2)){ |
| 18 | return true; |
| 19 | } |
| 20 | } |
| 21 | return false; |
| 22 | } |
| 23 | private boolean isMatched(int map1[], int map2[]){ |
| 24 | for(int i=0;i<26;i++){ |
| 25 | if(map1[i]!=map2[i]) return false; |
| 26 | } |
| 27 | return true; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | |
| 32 | // Sliding Window |
nothing calls this directly
no outgoing calls
no test coverage detected