Weird runtime error for test case: "AABABBA" 1


  • 0
    F

    Why my code got an runtime error for this test case:
    "AABABBA"
    1
    but in Visual studio, the result is right?

        int characterReplacement(string s, int k) {
            if(s.size() <= k) return s.size();
            
            int alphaCount[26] = {0};
            
            int first=0, last=0, maxCount=0;
            for(last=0; last<s.size(); ++last) {
                maxCount = max(maxCount, ++alphaCount[s[last] - 'A']);
                if(last - first + 1 - maxCount > k) {
                    alphaCount[s[first++]]--;
                }
            }
            
            return s.size() - first;
        }
    

  • 0
    L

    alphaCount[s[first++]]--; You forgot to -'A'


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.