题目:
代码:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29class Solution { public: int lengthOfLongestSubstring(string s) { //s[start,end) 前面包含 后面不包含 int start(0), end(0), length(0), result(0); int sSize = int(s.size()); while (end < sSize) { char tmpChar = s[end]; for (int index = start; index < end; index++) { if (tmpChar == s[index]) { start = index + 1; length = end - start; break; } } end++; length++; result = max(result, length); } return result; } };
思路:设置一个S[end],依次找出以S[end]结尾的最长无重复子串,取最大值即可
最后
以上就是刻苦汽车最近收集整理的关于LeetCode-3.无重复的最长子串的全部内容,更多相关LeetCode-3.无重复内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复