lintcode:Longest Substring Without Repeating Characters
来源:互联网 发布:学生赚软件下载 编辑:程序博客网 时间:2024/06/05 04:02
Given a string, find the length of the longest substring without repeating characters.
Example
For example, the longest substring without repeating letters for"abcabcbb"
is "abc"
, which the length is 3
.
For "bbbbb"
the longest substring is "b"
, with the length of 1
.
Challenge
O(n) time
class Solution {public: /** * @param s: a string * @return: an integer */ int lengthOfLongestSubstring(string s) { // write your code here vector<int> dp(s.size()+1); map<int, int> posMap; dp[0] = 0; int retMax = 0; for (int i=0; i<s.size(); i++) { if (posMap.count(s.at(i)) == 0) { dp[i+1] = dp[i]+1; } else { dp[i+1] = min(i-posMap[s.at(i)], dp[i]+1); } posMap[s.at(i)] = i; retMax = max(retMax, dp[i+1]); } return retMax; }};
0 0
- lintcode:Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- Longest Substring Without Repeating Characters
- 【Android】【Other】一些Android知识点
- 【JS总结】——Browser Object Model(BOM)
- 快速排序
- 第9周项目3-分数类中的运算符重载续(1)
- js运动-完美运动框架
- lintcode:Longest Substring Without Repeating Characters
- jquery基础之笔记(全)
- mfc C++类型转换
- javaScript高级程序设计阅读总结
- 格式转换说明符scanf,printf格式%大全/格式化输入输出
- Java面向对象之封装
- python的迭代器
- 第9周项目3-分数类中的运算符重载续(2)
- 第九周上机项目5 方程也是类