昨天在Letcode上做题,有这么一道题:
Given a string, find the length of the 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 a substring, “pwke” is a subsequence and not a substring.
查找当前字符串不重复的子串最大长度,我看难度等级是中等。我用go写了至少2个小时吧,总算是完成了,但是一提交测试,所有单元测试都通过了,但是,最后一个超时,就是执行时间太长了而被拒绝。昨天忘记记录下该测试用例,是一个很长很长的字符串,我写出来的代码983个单元测试,除了这个长串超时外其余982个都通过了。我苦思不得其解,后来去看了别人的答案,才知道之所以把这类问题归类为算法题的原因,肯定是不能用常规的思路去解决。确实高人挺多,我辈需要学习的东西实在是太多了。