Longest Substring Without Repeating Characters ---- LeetCode 003
Given a string, find the length of the longest substring without repeating characters. 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.
class Solution
{
public:
int lengthOfLongestSubstring(string s)
{
int len = s.length();
bool exist[maxn] = {false};
int maxLen = ; int i = , j = ;
while(j < len)
{
if(exist[s[j]])
{
maxLen = max(maxLen, j - i);
while(s[i] != s[j])
{
exist[s[i]] = false;
++i;
}
++i;
++j;
}
else
{
exist[s[j]] = true;
++j;
}
}
maxLen = max(maxLen, len - i);
return maxLen;
}
private:
const int maxn = ;
};
Longest Substring Without Repeating Characters ---- LeetCode 003的更多相关文章
- Longest Substring Without Repeating Characters leetcode java
题目: Given a string, find the length of the longest substring without repeating characters. For examp ...
- Longest Substring Without Repeating Characters -- LeetCode
原题链接: http://oj.leetcode.com/problems/longest-substring-without-repeating-characters/ 这道题用的方法是在LeetC ...
- 【JAVA、C++】LeetCode 003 Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. For example, ...
- 【LeetCode刷题系列 - 003题】Longest Substring Without Repeating Characters
题目: Given a string, find the length of the longest substring without repeating characters. Example 1 ...
- 【LeetCode】003. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. For example, ...
- leetcode: longest substring without repeating characters
July 16, 2015 Problem statement: Longest Substring Without Repeating Characters Read the blog: http: ...
- No.003:Longest Substring Without Repeating Characters
问题: Given a string, find the length of the longest substring without repeating characters.Example:Gi ...
- LeetCode 3 Longest Substring Without Repeating Characters(最长不重复子序列)
题目来源:https://leetcode.com/problems/longest-substring-without-repeating-characters/ Given a string, f ...
随机推荐
- HTML5自学笔记[ 24 ]canvas绘图之星空草地
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...
- sh脚本异常:bad interpreter: No such file or directory
转:http://bluedest.iteye.com/blog/1674963 在Linux中执行.sh脚本,异常/bin/sh^M: bad interpreter: No such file o ...
- Java文件编码格式转换
转自博文<Java文件编码格式转换>: 默认被转换的格式为GBK,转换成的格式为UTF-8 import info.monitorenter.cpdetector.CharsetPrint ...
- hdu 1520
Anniversary party Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others ...
- 318. Maximum Product of Word Lengths ——本质:英文单词中字符是否出现可以用26bit的整数表示
Given a string array words, find the maximum value of length(word[i]) * length(word[j]) where the tw ...
- python的一点小常识
在Python中,有两种变长参数,分别是元组(非关键字参数)和字典(关键字参数),其参数以一个*开头表示任意长度的元组[tuple],可以接收连续一串参数,参数以两个*开头表示一个字典[dict],即 ...
- git 将本地项目添加到远程
git init git add README.md git commit -m "first commit" git remote add origin git@github.c ...
- [apache]用shell分析网站的访问情况
随着网站正式运行,我们可以通过通用的免费日志分析工具比如awstats获得一些实际访问网站的信息,例如每天ip量,pv量,用户所用的的浏览器,用户所用的操作系统等,但是有时候希望通过手工方式从WEB日 ...
- .NET C#使用微信公众号登录网站
适用于:本文适用于有一定微信开发基础的用户 引言:花了300大洋申请了微信公众平台后,发现不能使用微信公众号登录网站(非微信打开)获得微信帐号.仔细研究后才发现还要再花300大洋申请微信开放平台才能接 ...
- NLTk
1.python的nltk中文使用和学习资料汇总帮你入门提高 http://blog.csdn.net/huyoo/article/details/12188573