Leet Code 3. Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters.
Examples:
Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring.
解题思路是建立一个映射表,检查两个重复字符之间的间隔长度。
int lengthOfLongestSubstring(string str)
{
// create table to store all ASCII
vector<int> vecTable(256,-1);
int nMaxLen = -1;
int nStart = -1;
for (int i = 0; i < str.length(); ++i)
{
// Target character's position is after previous location
if (vecTable[str[i]] > nStart)
{
nStart = vecTable[str[i]];
}
// Update target character's position;
vecTable[str[i]] = i;
nMaxLen = max(nMaxLen, i - nStart);
} return nMaxLen;
}
Leet Code 3. Longest Substring Without Repeating Characters的更多相关文章
- leetcode: longest substring without repeating characters
July 16, 2015 Problem statement: Longest Substring Without Repeating Characters Read the blog: http: ...
- (python)leetcode刷题笔记03 Longest Substring Without Repeating Characters
3. Longest Substring Without Repeating Characters Given a string, find the length of the longest sub ...
- [leetcode]3. Longest Substring Without Repeating Characters无重复字母的最长子串
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
- Leetcode:Longest Substring Without Repeating Characters 解题报告
Longest Substring Without Repeating Characters Given a string, find the length of the longest substr ...
- LeetCode第[3]题(Java):Longest Substring Without Repeating Characters 标签:Linked List
题目中文:没有重复字符的最长子串 题目难度:Medium 题目内容: Given a string, find the length of the longest substring without ...
- LeetCode题解 || Longest Substring Without Repeating Characters (O(n)算法)问题
problem: Given a string, find the length of the longest substring without repeating characters. For ...
- LeetCode[3] Longest Substring Without Repeating Characters
题目描述 Given a string, find the length of the longest substring without repeating characters. For exam ...
- [LeetCode] Longest Substring Without Repeating Characters 最长无重复子串
Given a string, find the length of the longest substring without repeating characters. For example, ...
- Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...
随机推荐
- CocoaPods 中删除不需要的第三方
1...打开Podfile 找到不需要的类库,直接删除 2...打开终端cd到当前项目的根目录下重新执行pod install --verbose --no-repo-update命令(更新一下) ...
- stylus入门学习笔记
title: stylus入门学习笔记 date: 2018-09-06 17:35:28 tags: [stylus] description: 学习到 vue, 有人推荐使用 stylus 这个 ...
- Js浮点运算存在精度问题
记得在某一次项目中,运用js进行一系列算数运算,计算中会存在浮点类型,就单纯的进行了计算,最后在测试过程中,主管在核对数据的时候发现计算的结果是有问题的,于是就很纳闷,在网上搜索找到了答案 ,htt ...
- spring环境搭建
1.导入jar包: 2.配置文件 — applicationContext.xml: 添加schema约束,位置:spring-framework-3.2.0.RELEASE—>docs—&g ...
- UNDO(二)
Managing Undo Beginning with Release 11g, for a default installation, Oracle Database automatically ...
- [Dababase - MySQL- Linux] 数据库安装位置
数据库安装最好是安装在 usr/local/ 里面,因为默认的很多东西都是指向这个文件夹中的.
- Spring mvc集成log4j2
前期环境 Spring mvc + Maven + Idea 一.下面开始配置log4j2,先简单演示其如何配置,再仔细了解log4j2用法. 1.1 配置pom.xml,引用log4j2相关包 & ...
- JVM调优之Tomcat启动加速(二)
使用 startup.bat 启动Tomcat 服务器时,start.bat 调用了bin 目录下的calalina.bat 文件. 如果需要配置 Tomcat的JVM参数,可以将参数写入 cata ...
- cron定时任务
1.确认系统安装了cron rpm -aq | grep crontabs 2.认识cron时间格式 3.生成定时任务 crontab -e #进入任务命令编辑模式 30 7,12,20 * * * ...
- Click event doesn't work on dynamically generated elements
I couldn't get live or delegate to work on a div in a lightbox (tinybox). I used setTimeout successf ...