Leetcode-Longest Substring Without Repeating Characters
来源:互联网 发布:spss输入数据是问号 编辑:程序博客网 时间:2024/06/06 08:52
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 asubstring, "pwke"
is a subsequence and not a substring.
Subscribe to see which companies asked this question.
以下代码为测试将返回结果改为了打印结果
#include<iostream>#include<stdio.h>#include<string>#include<vector>using namespace std;class Solution{public:void lengthOfLongestSubstring(string s) {int start = -1;int max = 0;vector<int> location(300, -1);for (int i = 0; i < s.size(); i++) {if (location[s[i]]>start)start = location[s[i]];if (i - start > max)max = i - start;location[s[i]] = i;}cout << max << endl;}};int main() {string s = "abcabcbb";Solution *p = new Solution;p->lengthOfLongestSubstring(s);system("pause");return 0;}
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
- caffe 添加YOLO新层Leaky Layer
- Hadoop学习之一
- 学习小结
- 注释的反面教材
- 0511
- Leetcode-Longest Substring Without Repeating Characters
- Android 获取本地外网IP、内网IP、计算机名等信息
- mysql拷贝表的几种方式
- Anaconda自定义配置以及远程登录jupyter
- 第一天练习练习博客怎么用
- linux权限与chmod命令
- 字符串转换为数字
- 爬取中国大学排名
- 保证分布式系统数据一致性的6种方案