Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public:
- int equalSubstring(string s, string t, int maxCost) {
- int ans = 0, left, right;
- for(left=0, right=0; right<s.length(); right++){
- maxCost -= abs(s[right]-t[right]);
- while(maxCost < 0) {
- maxCost += abs(s[left]-t[left]);
- left++;
- }
- ans = max(ans, right-left+1);
- }
- return ans;
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment