leetcode题解之Longest Substring Without Repeating Characters
来源:互联网 发布:内存数据库有哪些 编辑:程序博客网 时间:2024/06/13 23:27
借用了leetcode上的答案,自己还是太菜了,这里dict的长度为256是由于ASCII码总共能表示256个字符。
class Solution {
public:int lengthOfLongestSubstring(string s) {
vector<int> dict(256, -1);
//start表示初始位置,i表示结尾位置
int maxLen = 0, start = -1;for (int i = 0; i != s.length(); i++) {
//正常情况下dict[s[i]]是不可能大于start的,唯一的机会就是s[i]是一个与之前字符重复的字符,这种情况下需要把初始位置start移动到该重复字符的位置然后继续进行
if (dict[s[i]] > start)
start = dict[s[i]];
dict[s[i]] = i;
maxLen = max(maxLen, i - start);
}
return maxLen;
}
};
阅读全文
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题解之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之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
- EJB 概念
- Kubernetes之蓝绿部署
- Android ListView基本使用
- 【Angular2】CheckBox获取值的两种方式
- 求助贴
- leetcode题解之Longest Substring Without Repeating Characters
- 【操作系统】第二章小结
- Android模拟器Genymotion安装使用教程详解
- jQuery 事件
- 1499 图
- c#获取屏幕上某坐标点的颜色
- java获取屏幕上某坐标点的颜色
- Word Construction
- Vue实现简单ToDoList