[刷题] 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 ...
随机推荐
- 添加ASP.NET文件夹(3)
注意:这里添加的是ASP.NET文件夹,而不是普通网站下项目创建的文件夹 ASP.NET文件夹主要有7个 1.Bin文件夹包含程序所需的所有已编译程序集 2.App_Code文件夹包含页所使用的类的源 ...
- 一文彻底掌握Apache Hudi的主键和分区配置
1. 介绍 Hudi中的每个记录都由HoodieKey唯一标识,HoodieKey由记录键和记录所属的分区路径组成.基于此设计Hudi可以将更新和删除快速应用于指定记录.Hudi使用分区路径字段对数据 ...
- (二)基于商品属性的相似商品推荐算法——Flink SQL实时计算实现商品的隐式评分
系列随笔: (总览)基于商品属性的相似商品推荐算法 (一)基于商品属性的相似商品推荐算法--整体框架及处理流程 (二)基于商品属性的相似商品推荐算法--Flink SQL实时计算实现商品的隐式评分 ( ...
- 【剑指offer】8:跳台阶
题目描述: 一只青蛙一次可以跳上1级台阶,也可以跳上2级.求该青蛙跳上一个n级的台阶总共有多少种跳法(先后次序不同算不同的结果). 解题思路: 这种题目多为找规律求通用公式并最终用代码实现. 首先,考 ...
- pandas(5):数学统计——描述性统计
Pandas 可以对 Series 与 DataFrame 进行快速的描述性统计,方便快速了解数据的集中趋势和分布差异.源Excel文件descriptive_statistics.xlsx: 一.描 ...
- 2. Mybatis Select
mybatis select是mybatis 中最常用的元素之一. 对简单的查询,select 元素的配置是相当简单的: <?xml version="1.0" encodi ...
- Django--虚拟环境、项目和应用的创建
第一点:官方手册 -- https://yiyibooks.cn/ 第二点:运行环境 -- django项目采用虚拟运行环境 之前我们pip install都是在Python的安装目录(底层)上安装的 ...
- Spring Security极简入门三部曲(中篇)
目录 Spring Security极简入门三部曲(中篇) 验证流程 Authentication接口 过滤器链 AuthenticationProvider接口: demo时刻 代码讲解 小结 Sp ...
- 从苏宁电器到卡巴斯基第23篇:难忘的三年硕士时光 I
初次接触逆向工程 不知不觉就来到了2013年的9月份,学校开学了,我开始正式体验研究生的生活了.按道理来说,硕士研究生是需要围绕在导师身边,每天朝九晚五地去实验室做项目的.不过我们老师没有项目,也不要 ...
- CVE-2012-0158:Microsoft Office MSCOMCTL.ocx 栈溢出漏洞调试分析
0x01 Lotus Blossom 行动 在 2015 年 6 月,国外安全厂商 Palo Alto Networks 的威胁情报团队 Unit42 发现了一起针对东南亚政府的一次间谍行为,试图获取 ...