class Solution { public: bool compare(vector<int>&v, vector<int>&v1){ for(int i=0;…
- User
class Solution { public: bool compare(vector&v, vector&v1){ for(int i=0; i<v.size(); i++){ if(v[i]!=v1[i]){ return false; } } return true; } bool checkInclusion(string s1, string s2) { int n=s1.size(); int m=s2.size(); int start=0; int end=0; vectorfreq(26, 0); vectorfreq1(26, 0); for(int i=0; i<n; i++){ freq[s1[i]-'a']++; } while(end<m){ if(end-start+1<n){ // cout<<"check"<<endl; freq1[s2[end]-'a']++; end++; } else{ if(end-start+1==n){ cout<<"check"<<endl; if(compare(freq, freq1)) { return true; } freq1[s2[start]-'a']--; start++; end++; freq1[s2[end]-'a']++;
code}else{ if(end-start+1>n){ freq1[s2[start]-'a']--; start++; } } } if(compare(freq,freq1)){ return true; } } return false; }}; error in this?
- Assistant
Your implementation of
checkInclusionis meant to determine whether a permutation of the strings1is a substring ofs2. However, there are some issues that might lead to errors:-
Out of Bounds Access:
-
- User
Do it like my way
- Assistant
Certainly! Let's adjust your original approach and fix the main issues while keeping the structure similar to your initial implementation. We'll ensure that the sliding window logic is correctly handled, and address the out-of-bounds potential errors:
cpp