Leetcode - 3. Longest Substring Without Repeating Characters

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 the length of 3. Note that the answer must be asubstring,"pwke"is asubsequenceand not a substring.


非常typical 的题目,但是用暴力解法会超时(for pyhton only tough....damn python....)

暴力解法:

从第一个开始,check  这个字母是否出现在重复,没有的话counter+=1,else全部归零,把counter和上个最大值进行对比保留最大,java或者c应该就不会超时,python。。。。u know,...


Leetcode - 3. Longest Substring Without Repeating Characters_第1张图片
-

你可能感兴趣的:(Leetcode - 3. Longest Substring Without Repeating Characters)