Skip to content

Commit

Permalink
Minor changes afroz (#89)
Browse files Browse the repository at this point in the history
* add uncrossedLines.cpp file

* add changes
  • Loading branch information
afrozchakure authored Oct 1, 2023
1 parent f043afc commit 50cff49
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions LeetCode/Algorithms/Medium/PermutationInString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,29 @@ class Solution {
vector<int> s1_vec(26, 0);

for(auto c: s1) {
s1_vec(c - 'a')++;
s1_vec[c - 'a']++;
}

vector<int> s2_vec(26, 0);

int left = 0, right = 0;

while(right < n) {
s2_vec[s2[right] - 'a']++;
if((right - left + 1) == m) {
if(s1_vec == s2_vec) {
return true;
}
}

if((right - left + 1) < m) {

right++;
} else {
s2_vec[s2[left] - 'a']--;
left++;
right++;
}
}
return false;
}
};

0 comments on commit 50cff49

Please sign in to comment.