题目:

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. 个人psp

    排球计分程序 1.计划 通过对用户故事估计这个任务需要3~5d天. 2.开发 2.1需求分析 作为一个观众,我希望了解每场比赛的比分,以便了解比赛的情况. 作为一个观众,我希望输入球队名称查询球队比分 ...

  2. IOI2011ricehub米仓

    Description 乡间有一条笔直而长的路称为"米道".沿着这条米道上 R 块稻田,每块稻田的坐标均为一个 1 到 L 之间(含 1 和 L)的整数.这些稻田按照坐标以不减的顺 ...

  3. 开发微信小程序 中遇到的坑 及解决方法

    1.wx.request 只能访问 https 解决: 新建项目  不填appid  即可访问 localhost 2.页面中多重三元表达式  解析有问题 解决: <!--{{index}} { ...

  4. js倒计时跳转页面

    var t=10; setInterval(function refer(){ if(t>0){ document.getElementById("em").innerHTM ...

  5. C++ 指向成员函数指针问题

    成员函数指针与常规指针不同,一个指向成员变量的指针并不指向一个内存位置.通常最清晰的做法是将指向数据成员的指针看作为一个偏移量. class ru_m { public: typedef int (r ...

  6. 中文Locale

    sudo apt-get install locales dpkg-reconfigure locales 查看当前已安装locale: locale -a 查看locale设置: locale

  7. django-pagination 分页栏长度控制

    在分页页数很多时,分页样式会很长影响美观 我们可以用两个方式控制: 1.找到django-pagination里的pagination\pagination.html,在<ul class=&q ...

  8. [转+整理] Android 分辨率,密度,像素单位说明

    Android支持下列所有单位: px(像素):屏幕上的一个点.不同设备显示效果相同,一般我们HVGA代表320×480像素,这个用的比较多.in(英寸):长度单位.mm(毫米):长度单位.pt(磅) ...

  9. 艺萌文件上传下载及自动更新系统(基于networkComms开源TCP通信框架)

    1.艺萌文件上传下载及自动更新系统,基于Winform技术,采用CS架构,开发工具为vs2010,.net2.0版本(可以很容易升级为3.5和4.0版本)开发语言c#. 本系统主要帮助客户学习基于TC ...

  10. NetworkComms V3 模拟登陆

    演示NetworkComms V3的用法 例子很简单 界面如下: 服务器端代码: 开始监听: //服务器开始监听客户端的请求 Connection.StartListening(ConnectionT ...