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 ...
随机推荐
- echarts 角度渐变环形图心得
今天做了一个图,把自己的遇到的问题和体会记录一下,以防忘记 echarts地址 https://gallery.echartsjs.com/editor.html?c=xEPtLLmG4G 参考官网地 ...
- 在微信浏览器中 location.reload() 不刷新解决方案(直接调用方法)
1.问题 在微信浏览器中,需要时刷新当前页面. 正常情况下我们直接使用 location.reload 方法来刷新. 2.解决方法 function realod(){ var {search,hre ...
- VBA正则笔记 理解肯定环视
之前没有理解好,还以为是学习笔记有谬误. 'VBA正则笔记 肯定环视 Public Sub RegExHandle() Dim Regex As Object Dim Mh As Object, On ...
- Inquirer.js
一个使用界面进行交互的命令行集合 4.0以上的版本只支持node 6以上的,node4请使用3.x 目标和理念(hilosophy) 努力去做一个容易的 嵌入式的(embeddable) 和优美的命令 ...
- mysql修改当前用户的密码
ALTER USER USER() IDENTIFIED BY '123456';https://majing.io/posts/10000005531181
- winfrom导出DataGridView为Excel方法
声明:此方法需要电脑安装Excel软件 需要类库:Microsoft.Office.Interop.Excel.dll 可百度自行下载 方法代码: /// <summary> /// 导出 ...
- 用python代码模拟登录网站
方法一:直接使用已知的cookie访问 特点: 简单,但需要先在浏览器登录 具体步骤: 1.用浏览器登录,获取浏览器里的cookie字符串 先使用浏览器登录.再打开开发者工具,转到network选项卡 ...
- EDB日志配置-慢sql记录分析
1.打开:/postgresql的安装目录/data/postgresql.conf 2.找到并更改以下属性,其他的是方便观察设置的,注意要将属性前面的注释符'#'去掉才能生效 ★★★log_dest ...
- windows WebStorm常用快捷键记录,常用的都在这儿找扒
~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Webstorm version 2018.2 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 1. Ctrl + Shift + ...
- Spring框架中获取连接池的几种方式
什么是数据库连接池? 数据库连接池是一种关键的有限的昂贵的资源,对数据库连接的管理能显著影响到整个应用程序的伸缩性和健壮性,影响到程序的性能指标.数据库连接池就是用来解决这些问题而提出的. 数据库连接 ...