在一个字符串中寻找出最长的无重复字符的子串的,在不断的后续检索中需要去掉前面一个重复的字符,那么就是需要记录之前所出现过的字符的,在这里需要利用hashmap来记录字符和其出现的位置之间的映射关系的,在考虑移动更改坐标值的时候就是维护的一个滑动窗口的,这个窗口的最右端的就是当前遍历到的字符的位置然后来求出窗口的大小的,同时为了记录窗口的左边界需要使用left来定位左边界。在不断的扩充右边界的时候同时需要检查左边界的字符的,也就是需要移动left指针的,并且利用hashmap来记录对应的下标值,并且不断更新可能的最长长度的。

首先需要让所有的map都初始化为-1的结果然后是不断地更新值。初始化为-1是为了能够与对应的长度进行匹配的。

class Solution {
public:
int lengthOfLongestSubstring(string s) {
vector<int> m(,-);
int left=-,res=;
for(int i=;i<s.size();i++){
left=max(m[s[i]],left);
res=max(res,i-left);
m[s[i]]=i;
}
return res;
}
};

leetcode 3.Longest Substring Without Repeating Charcters的更多相关文章

  1. C++版- Leetcode 3. Longest Substring Without Repeating Characters解题报告

    Leetcode 3. Longest Substring Without Repeating Characters 提交网址: https://leetcode.com/problems/longe ...

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

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

  3. LeetCode 3 Longest Substring Without Repeating Characters 解题报告

    LeetCode 第3题3 Longest Substring Without Repeating Characters 首先我们看题目要求: Given a string, find the len ...

  4. [LeetCode][Python]Longest Substring Without Repeating Characters

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest ...

  5. LeetCode之Longest Substring Without Repeating Characters

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

  6. Leetcode 3. Longest Substring Without Repeating Characters (Medium)

    Description Given a string, find the length of the longest substring without repeating characters. E ...

  7. [Leetcode Week1]Longest Substring Without Repeating Characters

    Longest Substring Without Repeating Characters题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/longes ...

  8. [LeetCode] 3.Longest Substring Without Repeating Characters 最长无重复子串

    Given a string, find the length of the longest substring without repeating characters. Example 1: In ...

  9. LeetCode[3] Longest Substring Without Repeating Characters

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

随机推荐

  1. overture不同行的音符应该如何连线?

    钢琴初学者在使用overture的时候,碰到不同行中的音符想要将其连线,肯定会疑惑如何来完成这个操作.Overture作为一款钢琴爱好者喜爱的钢琴打谱作曲软件,有着十分强大的功能,下面,我们来看看如何 ...

  2. sql server 查询某个表被哪些存储过程调用

    sql server 查询某个表被哪些存储过程调用 select distinct object_name(id) from syscomments where id in (select id fr ...

  3. Python3 tkinter基础 Menu add_radiobutton 单选的下拉菜单

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  4. CSS常用伪类

    css伪类 :after 在元素后面插入内容 :hover 鼠标移入时进行 :before 在元素前面插入内容 :link 未选中的链接 :active 点击后产生什么变化 :nth-child 匹配 ...

  5. Selenium(基于JAVA语言)-》在eclipse上运行web项目在Mac系统上启动时提示nodename nor servname provided解决办法

    最近使用eclipse进行自动化测试时,遇到一种情况,无法调起浏览器,且有报错,如下: org.openqa.selenium.WebDriverException: failed to lookup ...

  6. python tar 打包

    import os import tarfile def make_targz_one_by_one(output_filename, source_dir): tar = tarfile.open( ...

  7. CSP中的选择

    P ∩ Q (P or Q) 由机器做出选择,环境无法控制,设计软件时只实现一个即可 P[]Q一般选择(Genral choice) 环境可以控制选择P或Q,若P不可接受这个动作,则执行Q,若Q不可接 ...

  8. 美国FLAG和中国BAT的比较(王益)

    美国FLAG和中国BAT的比较(王益) http://cxwangyi.github.io/notes/2014-09-29-flag-vs-bat.html 知乎 http://www.zhihu. ...

  9. 锯齿状优惠券css绘制

    对于图上优惠券左右两侧的半圆锯齿效果,两种处理方式,一种直接使用切图进行处理,一种是纯css进行效果绘制.切图的就不再赘述,主要说纯css效果绘制 绘制的结果如下图: 难点在于两侧的半圆孔是透明色,不 ...

  10. asp.net core2.1 bundleconfig.json合并压缩资源文件

    在asp.net core中则可以使用BuildBundlerMinifier来进行css,js的压缩合并 1.使用NuGet安装 BuildBundlerMinifier(也可以在vs中下载安装扩展 ...