Leetcode: 3. Longest Substring Without Repeating Characters
来源:互联网 发布:ubuntu软件中心下载 编辑:程序博客网 时间:2024/05/22 01:35
Leetcode: 3. Longest Substring Without Repeating Characters
一道一般的字符串问题,要求在给定字符串中找出不含重复字符的最长子串的长度。
思路
一个简单的思路是碰到重复的就回到上一个重复的字母的下一位开始找。
int lengthOfLongestSubstring(string s) { // Start typing your C/C++ solution below // DO NOT write int main() function int count[26]; if(s.size() ==0) return 0; memset(count,-1, sizeof(count)); int start = 0; int maxV = 0; for(int i=0; i< s.size(); i++) { int index = s[i] - 97; if(count[index] >= 0) { if(maxV < (i -start)) { maxV = i-start; } i = count[index]; start = i+1; memset(count,-1, sizeof(count)); continue; } count[index] = i; } if(maxV < (s.size() -start)) { maxV = s.size()-start; } return maxV; }
阅读全文
0 0
- [LeetCode]3.Longest Substring Without Repeating Characters
- LeetCode 3.Longest Substring Without Repeating Characters
- LeetCode --- 3. Longest Substring Without Repeating Characters
- [Leetcode] 3. Longest Substring Without Repeating Characters
- [leetcode] 3.Longest Substring Without Repeating Characters
- [leetcode] 3. Longest Substring Without Repeating Characters
- [Leetcode]3. Longest Substring Without Repeating Characters
- leetcode 3. Longest Substring Without Repeating Characters
- 【Leetcode】3. Longest Substring Without Repeating Characters
- leetcode 3. Longest Substring Without Repeating Characters
- LeetCode-3.Longest Substring Without Repeating Characters
- LeetCode 3.Longest Substring Without Repeating Characters
- LeetCode - 3.Longest Substring Without Repeating Characters
- Leetcode 3. Longest Substring Without Repeating Characters
- 3. Longest Substring Without Repeating Characters LeetCode
- (Leetcode)3. Longest Substring Without Repeating Characters
- leetcode 3. Longest Substring Without Repeating Characters
- LeetCode-3. Longest Substring Without Repeating Characters
- Java WebService 简单入门实例
- python3.6.1安装失败:Service Pack 1 is required to continue installation
- Android 数据库详解
- HandlerThread 与 IntentService 源码分析
- HorizontalScrollView重新layout之后自动滑动初始位置问题解决
- Leetcode: 3. Longest Substring Without Repeating Characters
- 欢迎使用CSDN-markdown编辑器
- python编码问题
- 关于js把时间戳转成日期格式的问题
- 数据中心的Yarn on Docker集群方案
- ospf路由过滤归纳(待续)
- Android”挂逼”修炼之行—微信实现本地视频发布到朋友圈功能
- VS2010链接cplex:“fatal error LNK1112: 模块计算机类型“X64”与目标计算机类型“x86”冲突”;
- ThreadLocal 源码解析