Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Solution {
- public int characterReplacement(String s, int k) {
- return Math.max(helper(s, k), helper(new StringBuilder(s).reverse().toString(), k));
- }
- public int helper(String s, int k) {
- int max = -1;
- int counter = 0;
- int k2 = k;
- for(int i = 0; i<s.length(); i++) {
- char candidate = s.charAt(i);
- counter = 1;
- k2 = k;
- for(int j = i +1; j<s.length();j++) {
- if(candidate == s.charAt(j)) {
- counter++;
- } else {
- if(k2>0) {
- k2--;
- counter++;
- } else {
- break;
- }
- }
- max = Math.max(counter, max);
- }
- }
- return max;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement