在一个字符串中寻找出最长的无重复字符的子串的,在不断的后续检索中需要去掉前面一个重复的字符,那么就是需要记录之前所出现过的字符的,在这里需要利用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. BZOJ 4480 [JSOI2013] 快乐的jyy

    思路 两个字符串都插入回文自动机中(每次重置last) 最后统计两个right集合的大小就好了 代码 #include <cstdio> #include <algorithm> ...

  2. Vue提供操作DOM的方法

    <div ref="wrapper"> Vue.js 提供了我们一个获取 DOM 对象的接口—— vm.$refs.在这里,我们通过了 this.$refs.wrapp ...

  3. HDU 5279 YJC plays Minecraft(NTT+分治)

    题意 有 \(n\) 个岛屿,第 \(i\) 个岛屿上有一张 \(a_i\) 的完全图.其中第 \(i\) 张完全图的 \(a_i\) 号节点和 \(i+1\) 号岛屿的 \(1\) 号节点有边相连( ...

  4. Vue常见组件

    每一个组件都是一个vue实例 每个组件均具有自身的模板template,根组件的模板就是挂载点 每个组件模板只能拥有一个根标签 子组件的数据具有作用域,以达到组件的复用 根组件 <div id= ...

  5. vue--使用vue-cli构建项目

    webpack是现在较流行的前端自动化工具,该工具可以帮助开发者打包代码,以减少需要手动的工作,可以提高开发效率. vue中提供了一个脚手架工具vue-cli,这个工具已经将webpack配置好了,使 ...

  6. 使用Wscript/cscript调用VB脚本

    ●强制用Wscript.exe执行 SET Wshell=CreateObject("Wscript.Shell") if lcase(right(Wscript.fullName ...

  7. Redis入门指南之三(入门)

    本节主要介绍Redis的5种数据类型,同时使用Python API来操作Redis,其中python版本为3.5, redis版本为4.0.2. redis-py 的API的使用可以分类为: (1)连 ...

  8. Dedecms V5.7 关于session

    在dedecmsv5.7里面使用session的话要注意开启方式!和PHP源码里的使用方式不一样!!! 开启session,前面必须要@ @session_start(); 启动session,前面必 ...

  9. 6月23 Ajax传地址

    利用Ajax将图片存入数据库的过程中可能会出现路径乱码或不一致的现象因此要对其进行编码解码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 ...

  10. 添加浏览器back操作时的响应事件

    https://blog.csdn.net/xcqingfeng/article/details/70800118 $(function(){ pushHistory(); window.addEve ...