Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Bug Report for longest-repeating-substring-with-replacement #3960

Closed
@khris190

Description

@khris190

Bug Report forhttps://neetcode.io/problems/longest-repeating-substring-with-replacement

i've an algorithm passing all of the tests that is not correct:

class Solution {public:    int characterReplacement(string s, int k) {        int left = 0;        int maxLen = 0;        int tmpK = k;        for(int right = 1; right < s.size(); right++){            if(s[right] != s[left]){                tmpK--;                if(tmpK < 0){                    do{                        left++;                    }while(s[left] == s[left-1]);                    right = left;                    tmpK = k;                }            }            if(maxLen < right - left + 1){                maxLen = right - left + 1;            }        }        int backLen = s.size() - left + tmpK;        if(maxLen < backLen){            maxLen = backLen;        }        if(maxLen > s.size()){            maxLen = s.size();        }        return maxLen;    }};

that code passes all of the tests but it's not 100% correct as it fails on a case
s="ABCDZZZ"
k=3
and
s="ABCDZZ"
k=3
i'd propose adding at least one of those test cases into the question

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp