3. Longest Substring Without Repeating Characters(难,重要)
来源:互联网 发布:imovie mac 教程 编辑:程序博客网 时间:2024/06/06 04:15
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.
Subscribe to see which companies asked this question
class Solution {public:int lengthOfLongestSubstring(string s) {if (s.empty()) return 0;if (s.size() == 1) return 1;vector<int> hash(256, -1);int i = 0, j = 1;int res = 0;hash[s[0]] = 0;while (j<s.size()){if (hash[s[j]] >= i){i = hash[s[j]] + 1;}hash[s[j]] = j;res = max(res, j - i + 1);j++;}return res;}};
0 0
- 3. Longest Substring Without Repeating Characters(难,重要)
- 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
- 3.Longest Substring Without Repeating Characters
- [Leetcode] 3. Longest Substring Without Repeating Characters
- 3.Longest Substring Without Repeating Characters
- 3. Longest Substring Without Repeating Characters
- 3.Longest Substring Without Repeating Characters
- 3.Longest Substring Without Repeating Characters
- 3.Longest Substring Without Repeating Characters
- 3. Longest Substring Without Repeating Characters
- [leetcode] 3.Longest Substring Without Repeating Characters
- 3.Longest Substring Without Repeating Characters
- [leetcode] 3. Longest Substring Without Repeating Characters
- 3. Longest Substring Without Repeating Characters
- [Leetcode]3. Longest Substring Without Repeating Characters
- LightOJ 1138 Trailing Zeroes (二分+阶乘分解+思维)
- C#关于For循环break,goto,return的应用
- API测试自动化
- rtp 解包h264
- Codeforces Round #368 (Div. 2) C Pythagorean Triples(构造勾股数)
- 3. Longest Substring Without Repeating Characters(难,重要)
- win7 caffe使用笔记——计算图像均值
- leetcode Set Matrix Zeroes
- Android之Http通信HttpConnection
- LA 3644并查集
- LruCache源码解析
- SPOJ COT(树上k大,主席树+LCA)
- FFmpeg音视频同步的问题
- 93.leetcode Restore IP Addresses(medium)[回溯 DFS]