Leetcode 3. Longest Substring Without Repeating Characters (Medium) (cpp)
来源:互联网 发布:软件精灵下载安装 编辑:程序博客网 时间:2024/05/22 06:31
Leetcode 3. Longest Substring Without Repeating Characters (Medium) (cpp)
Tag: Hash Table, Two Pointers, String
Difficulty: Medium
/*3. Longest Substring Without Repeating Characters (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) { int start = 0, max_len = 0; vector<int> last_position(255, -1); for (int i = 0; i < s.size(); i++){ if (last_position[s[i]] >= start){ max_len = max(i - start, max_len); start = last_position[s[i]] + 1; } last_position[s[i]] = i; } return max((int)s.size() - start, max_len); }};
0 0
- Leetcode 3. Longest Substring Without Repeating Characters (Medium) (cpp)
- 【leetcode】3. Longest Substring Without Repeating Characters 【medium】
- LeetCode 3. Longest Substring Without Repeating Characters [Medium]
- Leetcode解题笔记 3.Longest Substring Without Repeating Characters [Medium]
- 3. Longest Substring Without Repeating Characters (Medium)
- 3. Longest Substring Without Repeating Characters Medium
- 【LeetCode】(3)Longest Substring Without Repeating Characters(Medium)
- <LeetCode><Medium> 3 Longest Substring Without Repeating Characters
- LeetCode-3-Longest Substring Without Repeating Characters(穷举)-Medium
- LeetCode第三关:Longest Substring Without Repeating Characters --> Difficulty: Medium
- week3-leetcode #3-Longest Substring Without Repeating Characters[Medium]
- [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
- cv::inRange的作用,注意它的区间是闭区间,而不是开区间...
- MyEclipse 全局替换与选择替换
- android studio LeakCanary 找出内存泄漏
- 终于做了这个决定
- Qt学习之路(41): QTableWidget
- Leetcode 3. Longest Substring Without Repeating Characters (Medium) (cpp)
- Unreal Engine 4 —— 版本兼容的工作原理以及一些可优化项
- 简书---不错的博文网站
- 完成端口IOCP详解
- **JAVASCRIPT** 程序控制结构和函数
- PHP使用CURL详解
- java学习总结(16.07.12)java的内部类
- Java 并发专题 :闭锁 CountDownLatch 之一家人一起吃个饭
- 选中项目右键Git看不到,不能提交代码