[LeetCode] Longest Substring Without Repeating Characters
来源:互联网 发布:网络剧 有毒 全集 编辑:程序博客网 时间:2024/06/07 19:38
在后面发现重复的字符后,就把前面的重复字符及之前的全部去掉,像毛毛虫爬行一样,同时统计最大的子序列长度。
class Solution {public: int lengthOfLongestSubstring(string s) { if (s.size() < 2) { return s.size(); } int length = 0; for(int first = 0, last = 1; last < s.size(); ++last) { string sub = s.substr(first, last - first); string::size_type dup = sub.find(s[last]); if (dup != string::npos ){ first += (dup + 1); } int gap = last - first + 1; length = (length >= gap ? length : gap); } return length; }};
0 0
- LeetCode: Longest Substring Without Repeating Characters
- LeetCode Longest Substring Without Repeating Characters
- LeetCode: Longest Substring Without Repeating Characters
- [Leetcode] Longest Substring Without Repeating Characters
- leetcode 23: Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- LeetCode 3 - Longest Substring Without Repeating Characters
- [LeetCode]Longest Substring Without Repeating Characters
- leetcode Longest Substring Without Repeating Characters
- 【leetcode】 Longest Substring Without Repeating Characters
- LeetCode-Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- [LeetCode] Longest Substring Without Repeating Characters
- [leetcode] Longest Substring Without Repeating Characters
- LeetCode - Longest Substring Without Repeating Characters
- LeetCode 3: Longest Substring Without Repeating Characters
- leetcode-3:Longest Substring Without Repeating Characters
- leetcode之Longest Substring Without Repeating Characters
- Java:String和Date、Timestamp之间的转换
- wpa_supplicant 介绍
- 串口出问题,原来是串口线没有插紧
- cocos2dx使用第三方.so库,并且.so库生成到libs/armeabi下面
- android实现截图功能
- [LeetCode] Longest Substring Without Repeating Characters
- hdu 1007找最短距离的点
- select with reglar file descriptor
- gdb常用命令
- Android使用handler和Runnable结合,自定义View更新UI的Demo
- 粒子编辑器下载
- 未完待续的几个命令
- 使用 int? 来确保值类型也可为null
- 第5周作业-打字成绩判断程序TouchType