最長無重複子串 滑動視窗解法

2021-08-14 17:10:16 字數 574 閱讀 6448

class solution 

int n = s.length();

int r = 256;

int map = new int[r];//桶:字元的個數的

int left = 0, right = 0;//視窗的兩個指標

int maxlen = integer.min_value;//最後的結果

//boolean notsamechar = true;

//現在漏掉了一種情況,就是遍歷的結尾的時候都沒有遇到重複的(前面有可能有重複的判斷了)

//如:aeabcd,aea重複判斷了;但是在left指向1--e時,right從2變回到1,right++遍歷到結尾d時都沒有遇到相同的,所以要人為判斷一下

while(right < n)

if(right == n - 1)

right++;

}return maxlen == integer.min_value? 0 : maxlen;

}}

leetcode:find all anagrams in a string 滑動視窗方法總結

最長無重複子串

examples given abcabcbb the answer is abc which the length is 3.given bbbbb the answer is b with the length of 1.given pwwkew the answer is wke with t...

最長無重複子串

給定乙個字串,請找出其中無重複字元的最長子字串。例如,在 abcabcbb 中,最長無重複子串為 abc 其長度為3。在 pwwkew 最長無重複子串為 wke 其長度為3。注意是是子串,pwke 是子串行而不是子串。leetcode 首先試了試暴力搜尋,遍歷一次字串,遍歷過程中,對每個字元都有乙個...

最長無重複子串

最長無重複子串 兩種思路 一種是暴力解法 一種是動態規劃 package merchant public class maxnorepeat int record 0,maxlen 1,index 0 for int i 1 ilength i else len if maxlenreturn s....