Skip to content

Commit ae5cc5a

Browse files
committed
Runtime: 9 ms (Top 64.85%) | Memory: 7.7 MB (Top 51.71%)
1 parent 35bffd6 commit ae5cc5a

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
1+
// Runtime: 9 ms (Top 64.85%) | Memory: 7.7 MB (Top 51.71%)
12
class Solution {
23
public:
34
int equalSubstring(string s, string t, int maxCost) {
45
int l = 0, r = 0, currCost = 0, n = s.length(), maxLen = 0;
5-
6+
67
while(r < n) {
78
currCost += abs(s[r] - t[r]);
89
r++;
9-
10+
1011
while(currCost > maxCost) {
1112
currCost -= abs(s[l] - t[l]);
1213
l++;
1314
}
14-
15+
1516
maxLen = max(r - l, maxLen);
1617
}
17-
18+
1819
return maxLen;
1920
}
20-
};
21+
};

0 commit comments

Comments
 (0)