LeetCode: Longest Substring Without Repeating Characters
来源:互联网 发布:淘宝客软文范例 编辑:程序博客网 时间:2024/06/15 20:53
记录每个字符上次出现的位置,pri表示所有字符从pri+1开始都不重复
class Solution {
public:int lengthOfLongestSubstring(string s) {
// Start typing your C/C++ solution below
// DO NOT write int main() function
if(s=="")
return 0;
int pri,mNum,pi[26];
pri = -1, mNum = -1;
memset(pi,-1,sizeof(pi));
for(int i=0;i<s.length();i++){
if(pi[s[i]-'a']!=-1)
pri = max(pri,pi[s[i]-'a']);
pi[s[i]-'a'] = i;
if(mNum<i-pri)
mNum = i-pri;
}
return mNum;
}
};
- 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
- 翘课的同学,我要对你说
- system tap简单使用
- 菜鸟变大牛:计算机专业学习方法、书籍总结
- JavaBeans 学习笔记
- STD:: C++ STRING 详解
- LeetCode: Longest Substring Without Repeating Characters
- 新标签页缩略图变小,底部最近打开、应用商店等不见了
- 从内存中动态加载C++ DLL
- POJ 2083 Fractal (分形&分治)
- Multi-tenancy
- MQ、JMS以及ActiveMQ
- 用C语言实现Ping程序功能
- IOS-获取Model(设备型号)、Version(设备版本号)、app(程序版本号)等
- 手动卸载SQL Server时遇到无法读取IIsMimeMap表错误