题目:

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<int> dict(, -);
int maxLen = , start = -;
for (int i = ; i != s.length(); i++) {
if (dict[s[i]] > start)
start = dict[s[i]];
dict[s[i]] = i;
maxLen = max(maxLen, i - start);
}
return maxLen;
}
};

Longest Substring Without Repeating Characters(Difficulty: Medium)的更多相关文章

  1. LeetCode #003# Longest Substring Without Repeating Characters(js描述)

    索引 思路1:分治策略 思路2:Brute Force - O(n^3) 思路3:动态规划? O(n^2)版,错解之一:420 ms O(n^2)版,错解之二:388 ms O(n)版,思路转变: 1 ...

  2. LeetCode:Longest Substring Without Repeating Characters(最长不重复子串)

    题目链接 Given a string, find the length of the longest substring without repeating characters. For exam ...

  3. 19.Longest Substring Without Repeating Characters(长度最长的不重复子串)

    Level:   Medium 题目描述: Given a string, find the length of the longest substring without repeating cha ...

  4. LeetCode 3 Longest Substring Without Repeating Characters(最长不重复子序列)

    题目来源:https://leetcode.com/problems/longest-substring-without-repeating-characters/ Given a string, f ...

  5. 【leetcode】Longest Substring Without Repeating Characters (middle)

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  6. 3. Longest Substring Without Repeating Characters (ASCII码128个,建立哈西表)

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  7. LeetCode OJ:Longest Substring Without Repeating Characters(最长无重复字符子串)

    Given a string, find the length of the longest substring without repeating characters. For example, ...

  8. LeetCode第三题—— Longest Substring Without Repeating Characters(最长无重复子字符串)

    题目描述 Given a string, find the length of the longest substring without repeating characters. Example ...

  9. [Leetcode] 3.Longest Substring Without Repeating Characters(unordered_map)

    通过把未访问的结点放到unordered_map中来判断是否重复,代码如下: class Solution { public: int lengthOfLongestSubstring(string ...

随机推荐

  1. spring-boot 之 使用Admin监控应用

    https://yq.aliyun.com/articles/2322 ************************************* 摘要: Spring Boot提供的监控接口,例如: ...

  2. Android 开发如何选择轮子(转)

    一个项目的开发,我们不可能一切从0做起,如果真是这样,那同样要哭瞎.因此,善于借用已经做好的 "车轮" 非常重要,如: 网络访问框架:OKHttp.retrofit.android ...

  3. JavaScript函数定义和调用 变量作用域

     本文是笔者在看廖雪峰老师JavaScript教程时的个人总结   JavaScript中函数定义可以是这样的格式 function 函数名(参数) {     函数体 } 也可以是这样的格式     ...

  4. 初识less

    1 less 安装使用 安装 sudo npm install node-less 使用 mkdir less cd /less lessc demo1.less > test1.css les ...

  5. gulp教程之gulp-minify-css

    简介: 使用gulp-minify-css压缩css文件,减小文件大小,并给引用url添加版本号避免缓存.重要:gulp-minify-css已经被废弃,请使用gulp-clean-css,用法一致. ...

  6. How (not) to trigger a layout in WebKit

    As most web developers are aware, a significant amount of a script's running time may be spent perfo ...

  7. 《Javascript设计模式》笔记一js的表现力

    用不同方法完成同样一个任务:启动和停止动画. 1.过程式的程序设计: function startAnimation(){ ... } function stopAnimation(){ ... } ...

  8. Objective-C( Foundation框架 一 NSDictionary (NSMutaleDictionary))

    NSDictionary 不可变的字典 创建字典的方法 // 创建字典的方式 NSDictionary *dy = [NSDictionary dictionaryWithObject:@" ...

  9. OC语言中BOOL 和 bool 区别

    1.类型不同 BOOL为int型: bool为布尔型: 2.长度不同 bool只有一个字节: BOOL长度视实际环境来定,一般可认为是4个字节: 3.取值不同 bool取值false和true,是0和 ...

  10. Centos安装桌面环境(一个命令搞定)

    # yum groupinstall "X Window System" "GNOME Desktop Environment"