在一个字符串中寻找出最长的无重复字符的子串的,在不断的后续检索中需要去掉前面一个重复的字符,那么就是需要记录之前所出现过的字符的,在这里需要利用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. Springboot 上传excel并解析文件内容

    最近在做一个物业的系统,需要通过excel上传业主的信息,解析并入库. 参考:https://www.cnblogs.com/jyyjava/p/8074322.html 话不多说,直接上核心代码 i ...

  2. 王之泰201771010131《面向对象程序设计(java)》第七周学习总结

    王之泰201771010131<面向对象程序设计(java)>第七周学习总结 第一部分:理论知识学习部分 第五章 第五章内容深度学习: 继承:如果两个类存在继承关系,则子类会自动继承父类的 ...

  3. 关于vim的折叠

    参考: http://www.cnblogs.com/fakis/archive/2011/04/14/2016213.html 和 这篇文章: https://blog.csdn.net/benda ...

  4. 微信小程序wepy开发循环wx:for需要注意

    微信小程序wepy开发循环wx:for需要注意 item index值必须在wx:for之后使用 <view wx:for="{{tablist}}" class=" ...

  5. E: Unable to locate package git

    git can’t install 报错信息: root@281eef85bb5d:~# apt-get install git Reading package lists... Done Build ...

  6. P1122 最大子树和

    传送门 思路: 任意找一个点为树根.DFS 遍历树,如果子树和为负就直接跳过,不然就统计进答案.( 虽是任意取一点为根,但不一定从这个点出发能够取得最优解,要开一个 ans 记录一下最大值.) 标程: ...

  7. Zabbix4.0+第三方报警平台OneAlert监控报警

    1. 前言 告警将重要信息发送给运维「或者其他相关人」,及时发现并且处理问题.在所有开源监控软件里面,Zabbix 的告警方式无疑是最棒的.告警的方式各式各样,从 Email 告警到飞信.139/18 ...

  8. ranch流程处理图

    ranch是开发服务端管理模板,这个模板不大,写的很经典,方便并发管理,而且性能很优秀~~ 其中比较优秀的就有cowboy~~ 看了一下ranch的源码(版本v1.2.1 下载链接https://gi ...

  9. 【Java】【9】String Date Calendar之间的转换

    前言: 1, Calendar 转化 String 2, Calendar 转化 Date 3,Date 转化 String 4,Date 转化 Calendar 5,String 转化 Calend ...

  10. django2_开发web系统接口

    1.单独创建.../sign/views_if.py文件,开发添加发布会接口 from django.http import JsonResponse from cmdb.models import ...