Longest Substring Without Repeating Characters--LeetCode
来源:互联网 发布:sql去重 编辑:程序博客网 时间:2024/06/04 19:26
1.题目
Longest Substring Without Repeating Characters
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.
2.题意
找到最长无重复子串的长度
3.分析
遍历字符串,得到当前无重复的最新left字符
借助i-left得到最大长度
同时更新每个字符的最新位置
4.代码
class Solution {public: int lengthOfLongestSubstring(string s) { vector<int> m(256, -1); int result = 0, left = -1; for(int i = 0; i < s.size(); ++i) { left = max(left, m[s[i]]); result = max(result, i - left); m[s[i]] = i; } return result; }};
阅读全文
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
- python(二)mac环境(macOS10.12.6)下的python3.6使用mysql
- PHP上传图片并缩放
- ZOJ
- 再谈消息包和几张图
- IE兼容性问题
- Longest Substring Without Repeating Characters--LeetCode
- java中的字符,字符串,数字之间的转换
- linux初级命令
- TCP协议下的流量估算
- rpm方式安装Mysql
- 在Spring应用中发布Webservice服务
- NYOJ-ACM-Coin Test
- C 之 文件加解密
- 内容提供者——添加联系人