3.Longest Substring Without Repeating Characters
来源:互联网 发布:allrightsreserved软件 编辑:程序博客网 时间:2024/06/08 18:33
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<char> storage;bool flag = false; int max_length = 0;int length = s.length();for(int i = 0;i < length;i++){if(i == 0){storage.push_back(s[i]);max_length = 1;}else{for(vector<char>::iterator iter = storage.begin();iter != storage.end();iter++){if(s[i] == *iter){flag = true;break;}}if(!flag){storage.push_back(s[i]);if(storage.size() > max_length) max_length = storage.size();}else{//if(storage.size() > max_length) max_length = storage.size();int temp = 1;while(storage.back() != s[i]){storage.pop_back();temp++;}i -= temp;storage.clear();flag = false;}}}return max_length; }};
阅读全文
0 0
- [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
- leetcode 3. Longest Substring Without Repeating Characters
- 【Leetcode】3. Longest Substring Without Repeating Characters
- Java--浏览器
- P
- python 文件读取
- 摩尔定律
- 超文本与超媒体
- 3.Longest Substring Without Repeating Characters
- CS50 2017 Week1
- .net登录页面实现验证码验证
- 在苏州微软的三个月实习
- 奇异值分解(SVD)
- JS代码获得URL中的参数方法
- hadoop配置及启动
- 十六进制转十进制.h
- CSS实现文字竖向排版以及双实线的实现