要求

  • 在一个字符串中寻找没有重复字母的最长子串

举例

  • 输入: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的更多相关文章

  1. 刷题3. Longest Substring Without Repeating Characters

    一.题目 Longest Substring Without Repeating Characters,具体请自行搜索. 这个题目,我看了一下,经过一番思考,我觉得实现起来不是很复杂. 但要做到bug ...

  2. 【LeetCode刷题系列 - 003题】Longest Substring Without Repeating Characters

    题目: Given a string, find the length of the longest substring without repeating characters. Example 1 ...

  3. length of the longest substring without repeating character

    Given a string, find the length of the longest substring without repeating characters. 来源:力扣(LeetCod ...

  4. 3. Longest Substring Without Repeating Character[M] 最大不重复子串

    题目 Given a string, find the length of the longest substring without repeating characters. Example 1: ...

  5. 【LeetCode每天一题】Longest Substring Without Repeating Characters(最长无重复的字串)

    Given a string, find the length of the longest substring without repeating characters. Example 1:    ...

  6. Leetcode第三题《Longest Substring Without Repeating Characters》

    题目: Given a string, find the length of the longest substring without repeating characters. For examp ...

  7. LeetCode(2) || Add Two Numbers && Longest Substring Without Repeating Characters

    LeetCode(2) || Add Two Numbers && Longest Substring Without Repeating Characters 题记 刷LeetCod ...

  8. Leetcode 解题 Longest Substring without repeating charcater python

    原题: Given a string, find the length of the longest substring without repeating character For example ...

  9. LeetCode 3 Longest Substring Without Repeating Characters 解题报告

    LeetCode 第3题3 Longest Substring Without Repeating Characters 首先我们看题目要求: Given a string, find the len ...

随机推荐

  1. 我的xshell配色方案,绿色/护眼/留存/备份

    [mycolor] text(bold)=e9e9e9 magenta(bold)=ff00ff text=00ff80 white(bold)=fdf6e3 green=80ff00 red(bol ...

  2. 从零搭建一个IdentityServer——会话管理与登出

    在上一篇文章中我们介绍了单页应用是如何使用IdentityServer完成身份验证的,并且在讲到静默登录以及会话监听的时候都提到会话(Session)这一概念,会话指的是用户与系统之间交互过程,反过来 ...

  3. python基础(十):集合的使用(上)

    集合的作用 去重:把一个列表变成集合,就自动去重了. 关系测试:测试两组数据之前的交集.差集.并集等关系. 集合的特征 集合使用 set 表示: 集合也使用{ }表示, 与字典不同的是:字典中存储的是 ...

  4. AgileConfig - 轻量级配置中心1.2.0发布,全新的UI✨✨✨

    AgileConfig自发布以来有个"大问题"-UI太丑.因为当初这个项目是给自己用的,连UI界面都没有,全靠手动在数据库里改配置.后来匆匆忙忙使用bootstrap3简单的码了一 ...

  5. Apache Hudi C位!云计算一哥AWS EMR 2020年度回顾

    1. 概述 成千上万的客户在Amazon EMR上使用Apache Spark,Apache Hive,Apache HBase,Apache Flink,Apache Hudi和Presto运行大规 ...

  6. Spring Security OAuth2 实现登录互踢

    背景说明 一个账号只能一处登录,类似的业务需求在现有后管类系统是非常常见的. 但在原有的 spring security oauth2 令牌方法流程(所谓的登录)无法满足类似的需求. 我们先来看 To ...

  7. Crackme_003

    功能: 拿到文件,先执行一下.功能如下: 1.nag窗口 会先出现如下nag窗口,持续几秒 2.注册窗口: 出现错误会提示:You Get Wrong  Try Again 破解: 1.查壳: 无壳, ...

  8. JAVAEE_01_什么是javaEE

    javaEE Java平台包含三个版本: - JavaME :适用于小型设备和智能卡的JavaME (Java Platform Micro Edition,Java微型版) - JavaSE : 适 ...

  9. 软件调研——GoodNotes 5与Notability

    项目 内容 这个作业属于哪个课程 2021春季软件工程(罗杰 任健) 这个作业的要求在哪里 作业要求 我在这个课程的目标是 积累软件开发经验,提高工程能力 这个作业在哪个具体方面帮助我实现目标 深入调 ...

  10. wordpress 自定义路由及展示页

    wordpress 自定义路由及展示页 注册domain/test这个路由 wordpress 有重写url的方法,叫 add_rewrite_rule().在function.php中加入如下代码段 ...