[刷题] 3 Longest Substring Without Repeating Character
要求
- 在一个字符串中寻找没有重复字母的最长子串
举例
- 输入:abcabcbb
- 输出:abc
细节
- 字符集?字母?数字+字母?ASCII?
- 大小写是否敏感?
思路
- 滑动窗口
- 如果当前窗口没有重复字母,j右移,直到包含重复字母
- i右移,直到不包含重复字母
- 用数组记录字母是否出现过,判断重复

实现
1 class Solution{
2 public:
3 int lenthOfLongestSubstring(string s){
4 int freq[256] = {0};
5 int l = 0, r = -1;
6 int res = 0;
7
8 while(l < s.size()){
9 if( r + 1 < s.size() && freq[s[r+1]] == 0)
10 freq[s[++r]] ++ ;
11 else
12 freq[s[l++]] -- ;
13 res = max(res, r-l+1);
14 }
15 return res;
16 }
17 };
相关
- 438 Find All Anagrams in a String
- 76 Minimum Window Substring
[刷题] 3 Longest Substring Without Repeating Character的更多相关文章
- 刷题3. Longest Substring Without Repeating Characters
一.题目 Longest Substring Without Repeating Characters,具体请自行搜索. 这个题目,我看了一下,经过一番思考,我觉得实现起来不是很复杂. 但要做到bug ...
- 【LeetCode刷题系列 - 003题】Longest Substring Without Repeating Characters
题目: Given a string, find the length of the longest substring without repeating characters. Example 1 ...
- length of the longest substring without repeating character
Given a string, find the length of the longest substring without repeating characters. 来源:力扣(LeetCod ...
- 3. Longest Substring Without Repeating Character[M] 最大不重复子串
题目 Given a string, find the length of the longest substring without repeating characters. Example 1: ...
- 【LeetCode每天一题】Longest Substring Without Repeating Characters(最长无重复的字串)
Given a string, find the length of the longest substring without repeating characters. Example 1: ...
- Leetcode第三题《Longest Substring Without Repeating Characters》
题目: Given a string, find the length of the longest substring without repeating characters. For examp ...
- LeetCode(2) || Add Two Numbers && Longest Substring Without Repeating Characters
LeetCode(2) || Add Two Numbers && Longest Substring Without Repeating Characters 题记 刷LeetCod ...
- Leetcode 解题 Longest Substring without repeating charcater python
原题: Given a string, find the length of the longest substring without repeating character For example ...
- LeetCode 3 Longest Substring Without Repeating Characters 解题报告
LeetCode 第3题3 Longest Substring Without Repeating Characters 首先我们看题目要求: Given a string, find the len ...
随机推荐
- 你才不是只会理论的女同学-seata实践篇
本文主要内容为seata的实践篇,理论知识不懂的请参考前文: 我还不懂什么是分布式事务 主要介绍两种最常用的TCC和AT模式. 环境信息: mysql:5.7.32 seata-server:1.4. ...
- Spring Cloud 升级之路 - 2020.0.x - 3. Undertow 的 accesslog 配置
上一节我们讲述了如何使用 Undertow 作为我们的 Web 服务容器,本小节我们来分析使用 Undertow 的另一个问题,也就是如何配置 accesslog,以及 accesslog 的各种占位 ...
- Java中注释的形式
单行注释 单行注释 // #双斜杠 快捷键:Ctrl + / 多行注释 多行注释 /* */ #单斜杠星号 星号单斜杠 快捷键:Ctrl + shift + / 文档注释 多行注释 /** */ #单 ...
- 算法图解...pdf
电子书资源:算法图解 书籍简介 本书示例丰富,图文并茂,以让人容易理解的方式阐释了算法,旨在帮助程序员在日常项目中更好地发挥算法的能量.书中的前三章将帮助你打下基础,带你学习二分查找.大O表示法. ...
- 动态扩展磁盘(LVM)
使用gtp格式磁盘为lvm类型 [root@elk-log-srv01 ~]# parted /dev/vdd GNU Parted 3.1 Using /dev/vdd Welcome to GNU ...
- GridSearchCV 参数
GridSearchCV(estimator, param_grid, scoring=None, fit_params=None, n_jobs=1, iid=True, refit=True, c ...
- 【cypress】3. 编写第一个测试
当环境安装好了之后,就可以着手尝试第一个测试的编写了. 一.新建一个文件 在你的项目下的cypress/integration文件夹中创建一个新文件sample_spec.js,我这里直接在webst ...
- hdu3622 二分+2sat
题意: 给你N组炸弹,每组2个,让你在这N组里面选取N个放置,要求(1)每组只能也必须选取一个(2)炸弹与炸弹之间的半径相等(3)不能相互炸到对方.求最大的可放置半径. 思路: 二 ...
- Android Studio导入Android 4.4.4r1的源码
本文博客地址:http://blog.csdn.net/qq1084283172/article/details/70339471 一.环境配置 1.ubuntu 14.04.5 x64bit 2.j ...
- Android Apk加固的初步实现思路(dex整体加固)
一.前 言 Android Apk加固的发展已经有一段时间了,相对来说本篇博客要记录的Android加壳的实现思路是4年的东西了,已经被老鸟玩烂了,Android加固的安全厂商也不会采用这么粗犷的方式 ...