leetcode 3.Longest Substring Without Repeating Charcters
在一个字符串中寻找出最长的无重复字符的子串的,在不断的后续检索中需要去掉前面一个重复的字符,那么就是需要记录之前所出现过的字符的,在这里需要利用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的更多相关文章
- C++版- Leetcode 3. Longest Substring Without Repeating Characters解题报告
Leetcode 3. Longest Substring Without Repeating Characters 提交网址: https://leetcode.com/problems/longe ...
- LeetCode 3 Longest Substring Without Repeating Characters(最长不重复子序列)
题目来源:https://leetcode.com/problems/longest-substring-without-repeating-characters/ Given a string, f ...
- LeetCode 3 Longest Substring Without Repeating Characters 解题报告
LeetCode 第3题3 Longest Substring Without Repeating Characters 首先我们看题目要求: Given a string, find the len ...
- [LeetCode][Python]Longest Substring Without Repeating Characters
# -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest ...
- LeetCode之Longest Substring Without Repeating Characters
[题目描述] Given a string, find the length of the longest substring without repeating characters. Exampl ...
- Leetcode 3. Longest Substring Without Repeating Characters (Medium)
Description Given a string, find the length of the longest substring without repeating characters. E ...
- [Leetcode Week1]Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/longes ...
- [LeetCode] 3.Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. Example 1: In ...
- LeetCode[3] Longest Substring Without Repeating Characters
题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...
随机推荐
- pageUtil分页工具
分页工具: https://www.cnblogs.com/ggq-insist-qiang/articles/10095603.html
- 使用redis做分布式锁
1.使用setnx命令.先看下官方文档http://redis.cn/commands/setnx.html 2.使用getset命令.先获取,再set 实现案例: * create 2018-12- ...
- react的dva框架初试
使用背景:迫不得已!!(自己入职是以vue技术入职的,说是马上vue项目就来了,让我负责这个项目的前端.但是入职后就让我下了现在这个项目看下,然后就顺理成章的帮忙进行开发了,其实自己一直想要做reac ...
- 解决 ln -s 软链接产生的Too many levels of symbolic links错误
参考: ln -s 软链接产生Too many levels of symbolic links错误 解决 ln -s 软链接产生的Too many levels of symbolic links错 ...
- C#设置IE代理
public class IEProxySetting { public static bool UnsetProxy() { return SetProxy(null, null); } publi ...
- 线程(六)之LOCK和synchronized
在java.util.concurrent.locks包中有很多Lock的实现类,常用的有ReentrantLock.ReadWriteLock(实现类ReentrantReadWriteLock), ...
- ES6标准之基础
let和const命令 ES6新增let命令,用于声明变量,是块级作用域. let声明的变量不会像var声明的变量发生“变量提升”现象,所以,变量一定要在声明后使用,不然就会报错. 暂时性死区:只要块 ...
- Hibernate向数据库存入BLOB和CLOB类型的数据
我选用的是byte[] +@Lob 刚开始采用的java.sql.Blob,将上传的图片getBytes()后,通过Hibernate.getLobCreator(HibernateSessionFa ...
- js中defer实现等文档加载完在执行脚本
我们可以使用defer来实现类似window.onload的功能: <script src="../CGI-bin/delscript.js" defer></s ...
- grpc(二)记一次grpc debug--io.grpc.StatusRuntimeException: UNKNOWN
1.起初是dingding一直报错: instance:服务器名 err:GrpcClient#placeOrder: io.grpc.StatusRuntimeException: UNKNOWN ...