Advertisement
nikunjsoni

567

Apr 17th, 2021
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.51 KB | None | 0 0
  1. class Solution {
  2. public:
  3.     bool checkInclusion(string s1, string s2) {
  4.         int map[26] = {0};
  5.         int left, right, count;
  6.         count = s1.length();
  7.         for(char c: s1) map[c-'a']++;
  8.        
  9.         for(left=0, right=0; right<s2.length(); right++){
  10.             if(map[s2[right]-'a']-- > 0) count--;
  11.             if(right-left+1 > s1.length()){
  12.                 if(map[s2[left++]-'a']++ >= 0) count++;
  13.             }
  14.             if(!count) return true;
  15.         }
  16.         return false;
  17.     }
  18. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement