https://oj.leetcode.com/problems/longest-substring-without-repeating-characters/

给一个string,找出其中不含有重复元素的最长子串的长度。

class Solution {
public:
int lengthOfLongestSubstring(string s) {
if(s.size() == || s.size() == )
return s.size(); map<char,int> map_record; int max_len = ;
int len = ;
for(int i = ; i < s.size(); i++)
{
len++; //维护当前的没有相同元素的范围长度
if(map_record.count(s[i]) != && map_record[s[i]] > i - len) //如果存在相同的元素,并且这个元素是在当前范围之内的
len = i - map_record[s[i]]; //更新当前范围的长度
map_record[s[i]] = i; max_len = max_len < len ? len : max_len;
}
return max_len;
}
};

LeetCode OJ-- Longest Substring Without Repeating Characters ***@的更多相关文章

  1. C++版- Leetcode 3. Longest Substring Without Repeating Characters解题报告

    Leetcode 3. Longest Substring Without Repeating Characters 提交网址: https://leetcode.com/problems/longe ...

  2. [LeetCode][Python]Longest Substring Without Repeating Characters

    # -*- coding: utf8 -*-'''__author__ = 'dabay.wang@gmail.com'https://oj.leetcode.com/problems/longest ...

  3. LeetCode 3 Longest Substring Without Repeating Characters(最长不重复子序列)

    题目来源:https://leetcode.com/problems/longest-substring-without-repeating-characters/ Given a string, f ...

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

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

  5. LeetCode之Longest Substring Without Repeating Characters

    [题目描述] Given a string, find the length of the longest substring without repeating characters. Exampl ...

  6. Leetcode 3. Longest Substring Without Repeating Characters (Medium)

    Description Given a string, find the length of the longest substring without repeating characters. E ...

  7. [Leetcode Week1]Longest Substring Without Repeating Characters

    Longest Substring Without Repeating Characters题解 原创文章,拒绝转载 题目来源:https://leetcode.com/problems/longes ...

  8. [LeetCode] 3.Longest Substring Without Repeating Characters 最长无重复子串

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

  9. LeetCode[3] Longest Substring Without Repeating Characters

    题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...

  10. 【leetcode】Longest Substring Without Repeating Characters

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

随机推荐

  1. PSTR、LPSTR等宏原型

    1.首先介绍char.wchar_t ,宽字符wchar_t和窄字符char. 窄字符char了,大家都很清楚,就是8bit表示的byte,长度固定.char字符只能表示ASII码表中的256个字符, ...

  2. 2017 ACM-ICPC EC-Final ShangHai(思维乱搞赛)

    感觉全是思维乱搞题. Gym - 101775J Straight Master 给你n种扑克,你每次可以出连续的3 ~ 5 张,问你能否出完. Sample Input 2 13 1 2 2 1 0 ...

  3. 连续小波变换CWT(2)

    如果让你说说连续小波变换最大的特点是什么?多分辨分析肯定是标准答案.所谓多分辨分析即是指小波在不同频率段会有不同的分辨率.具体表现形式,我们回到前一篇文章的第一个图, 图一 对应的信号为 低频时(频率 ...

  4. loj2308 「APIO2017」商旅

    ref #include <iostream> #include <cstring> #include <cstdio> #include <queue> ...

  5. 【Plus One】cpp

    题目: Given a non-negative number represented as an array of digits, plus one to the number. The digit ...

  6. 数据库脚本开发日志模板 —— 项目需求 A

    前言: 在经历的几家公司的多个项目开发管理中,用 git 或者 svn来管理项目代码,都着重项目代码的管理,却疏于相应脚本的管理.本文可以参考,作为项目需求对应脚本开发记录文件(也建议用单个文件夹下放 ...

  7. selenium随笔

    1.点击一个连接通常录制一个click命令,通常需要改变它到clickAndWait命令,确保案例暂停,新的页面完全被转载进来. 2.测试案例需要检查Web页的属性,需要assert和verify命令 ...

  8. PAT——乙级1008

    1008 数组元素循环右移问题 (20 point(s)) 一个数组A中存有N(>0)个整数,在不允许使用另外数组的前提下,将每个整数循环向右移M(≥0)个位置,即将A中的数据由(A​0​​A​ ...

  9. linux下telnet安装与使用

    现在管理linux基本都用crt.xshell或者putty,已经没什么人用telnet,因为后续需要讲zabbix免客户端监控只telnet,通过telnet来监控服务器性能. yum安装telne ...

  10. POJ 1990:MooFest(树状数组)

    题目大意:有n头牛,第i头牛声调为v[i],坐标为x[i],任意两值牛i,j沟通所需的花费为abs(x[i]-x[j])*max(v[i],v[j]),求所有牛两两沟通的花费. 分析: 我们将奶牛按声 ...