3. Longest Substring Without Repeating Characters——LeetCode OJ
来源:互联网 发布:淘宝网首页登录 编辑:程序博客网 时间:2024/05/17 04:16
Difficulty:Medium
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given “abcabcbb”, the answer is “abc”, which the length is 3.
Given “bbbbb”, the answer is “b”, with the length of 1.
Given “pwwkew”, the answer is “wke”, with the length of 3. Note that the answer must be a substring, “pwke” is a subsequence and not a substring.
给定一个字符串,找出其中没有重复字母的最长子串。注意答案必须是子串(父串中相连的子母)而不是仅为顺序链。
class Solution {public: int lengthOfLongestSubstring(string s) { vector<int> table(256,-1);//字符最近一次出现的位置 int start = -1;//记录最长无重复子串的前一个位置 int maxLength = 0; for(int i = 0; i < s.length(); ++i) { if(table[s[i]] >= start) { start=table[s[i]];//最近一次出现位置在start后,重复,更新start } table[s[i]] = i; maxLength = max(maxLength, i-start); } return maxLength; }};
Runtime: 22 ms
阅读全文
0 0
- 3. Longest Substring Without Repeating Characters——LeetCode OJ
- LeetCode OJ:Longest Substring Without Repeating Characters
- LeetCode OJ Longest Substring Without Repeating Characters
- LeetCode OJ ---- Longest Substring Without Repeating Characters
- [LeetCode OJ]Longest Substring Without Repeating Characters
- <LeetCode OJ> 3. Longest Substring Without Repeating Characters
- LeetCode OJ 3.Longest Substring Without Repeating Characters
- LeetCode OJ 3. Longest Substring Without Repeating Characters
- LeetCode OJ(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
- ssm整合MongoDb启动时出现无法将名称 'repository:auditing-attributes' 解析为 'attribute group' 组件异常
- 10.5——10.26 组合数学训练
- 高并发秒杀之秒杀优化
- 加载easyui下拉框
- 安卓开发-尺寸单位+Logcat的使用+Android单元测试+安卓系统中数据的读写
- 3. Longest Substring Without Repeating Characters——LeetCode OJ
- SpringMVC源码研究之DispatcherServlet初始化
- Netty--心跳
- RxJava 1
- C语言实验——三个数排序
- <基础原理进阶>机器学习算法python实现【5】--文本分析之支持向量机SVM(下)
- JS的Dom和事件处理机制( 一)
- C语言实现线性表的链式存储结构
- 嵌入式shell学习笔记