[刷题] 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 ...
随机推荐
- SpringCloud(六)分布式事务
在分布式系统中,分布式事务基本上是绕不开的, 分布式事务是指事务的参与者.支持事务的服务器.资源服务器以及事务管理器分别位于不同的分布式系统的不同节点之上 .其实就可以简单理解成在分布式系统中实现事务 ...
- JS基础学习第一天
JavaScript JavaScript负责页面中的的行为. 它是一门运行在浏览器端的脚本语言. JS的编写的位置 1.可以编写到标签的指定属性中 12 <button onclick=&qu ...
- 开源一周岁,MindSpore新特性巨量来袭
摘要:MindSpore很多新特性与大家见面了,无论是在效率提升.易用性,还是创新方面,都是干货满满. 最近,AI计算框架是业界的热点,各大厂商纷纷投身AI框架的自研发,究其原因:AI框架在整个人工智 ...
- 【软件推荐】利用Stylus修改网页显示字体
Windows下,字体的显示总是让人抓狂.抗锯齿效果让汉字显得粗细不均,甚至无法对齐的情况. 为了改善网页的显示效果,可以利用Stylus进行字体的替换 Stylus可以在Google的商店下载,由于 ...
- (6)MySQL进阶篇SQL优化(MyISAM表锁)
1.MySQL锁概述 锁是计算机协调多个进程或线程并发访问某一资源的机制.在数据库中,除传统的计算资源 (如 CPU.RAM.I/O 等)的抢占以外,数据也是一种供许多用户共享的资源.如何保证数 据并 ...
- 【CTF】XCTF 我们的秘密是绿色的 writeup
题目来源:SSCTF-2017 题目链接:https://adworld.xctf.org.cn/task/answer?type=misc&number=1&grade=1& ...
- NTP时间同步服务
NTP时间服务器 作用:ntp主要是用于对计算机的时间同步管理操作. 时间是对服务器来说是很重要的,一般很多网站都需要读取服务器时间来记录相关信息,如果时间不准,则可能造成很大的影响. 部署安装NTP ...
- HashSet、CopyOnWriteArraySet、ConcurrentSkipListSet源码解析(JDK1.8)
目录 HashSet源码解析 HashSet简单使用的demo HashSet中的变量 HashSet的构造函数 HashSet的add方法 HashSet的iterator方法 HashSet的si ...
- C#中普通缓存的使用
缓存的概念及优缺点在这里就不多做介绍,当然缓存包含多种有普通缓存.客户端缓存.DNS缓存.反向代理缓存以及分布式缓存等等.今天主要聊一聊C#通过编码来实现普通的缓存.话不多说直接上代码. 一.首先,新 ...
- 07- 移动端app弱网测试与fiddle弱网测试
从下面几个点了解弱网测试: 什么样的网络属于弱网. 低于2g速率的时候都属于弱网,也可以将3g划分为弱网,一般WiFi不纳入弱网范畴. 为什么要进行弱网测试 ①按照移动特定,各种网络连接协议不同,导致 ...