3. Longest Substring Without Repeating Characters (ASCII码128个,建立哈西表)
Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the length is 3. For "bbbbb" the longest substring is "b", with the length of 1.
int lengthOfLongestSubstring(char* s) {
int latestPos[]; //map<char,int>
int result = ;
int i = ;
int startPos = ;
if(strcmp(s,"")==) return result;
memset(latestPos, -, sizeof(latestPos));
latestPos[s[]] = ;
while(s[i]!='\0'){
if(latestPos[s[i]] >= startPos){ //s[i] already appeared
if(i-startPos > result) result = i-startPos;
startPos = latestPos[s[i]]+;
}
latestPos[s[i]] = i;
i++;
}
if(i-startPos > result) result = i-startPos;
return result;
}
3. Longest Substring Without Repeating Characters (ASCII码128个,建立哈西表)的更多相关文章
- LeetCode longest substring without repeating characters 题解 Hash表
题目 Given a string, find the length of the longest substring without repeating characters. Example 1: ...
- 【一天一道LeetCode】 #3 Longest Substring Without Repeating Characters
一天一道LeetCode (一)题目 Given a string, find the length of the longest substring without repeating charac ...
- Leetcode经典试题:Longest Substring Without Repeating Characters解析
题目如下: Given a string, find the length of the longest substring without repeating characters. Example ...
- C++版- Leetcode 3. Longest Substring Without Repeating Characters解题报告
Leetcode 3. Longest Substring Without Repeating Characters 提交网址: https://leetcode.com/problems/longe ...
- Leetcode:Longest Substring Without Repeating Characters 解题报告
Longest Substring Without Repeating Characters Given a string, find the length of the longest substr ...
- 《LeetBook》leetcode题解(3):Longest Substring Without Repeating Characters[M]——哈希判断重复
我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...
- [LeetCode]3. Longest Substring Without Repeating Characters无重复字符的最长子串
Given a string, find the length of the longest substring without repeating characters. Example 1: In ...
- LeetCode Longest Substring Without Repeating Characters 最长不重复子串
题意:给一字符串,求一个子串的长度,该子串满足所有字符都不重复.字符可能包含标点之类的,不仅仅是字母.按ASCII码算,就有2^8=128个. 思路:从左到右扫每个字符,判断该字符距离上一次出现的距离 ...
- 【LeetCode】3 、Longest Substring Without Repeating Characters
题目等级:Medium 题目描述: Given a string, find the length of the longest substring without repeating chara ...
随机推荐
- idea 一款神一样的编辑器 IDEA,破解方式
功能1,可以开发后端如 JAVA, PHP, PYTHON ,NODE 功能2,可以开发前端如 HTML + CSS + JS 破解方式 1,编辑C:\Windows\System32\driver ...
- 来分析一个UVC的摄像头的枚举信息
使用到工具USBlyzer导出数据,但是会发现一些还有部分解析未完全.我们将借助UVCView.x86(https://files.cnblogs.com/files/libra13179/77772 ...
- day03-数据类型
数据类型 一.介绍 存储引擎决定了表的类型,而表内存放的数据也要有不同的类型,每种数据类型都有自己的宽度,但宽度是可选的 mysql常用数据类型概括:#1. 数字: 整型:tinyint.int.bi ...
- HBase 入门
使用条件: 海量数据百亿级的行 百万列, 准实时查询 使用场景: 比如金融,交通,电商,移动等 特点: 1:
- html to docx
public static void main(String[] args) throws Exception{ //创建 POIFSFileSystem 对象 POIFSFileSystem poi ...
- XML中的变量传值
在action的java类中定义变量之后,在XML中获取该变量进行对应传值:: 在指定方法中获取XML配置文件的变量传值::
- Think you can pronounce these 10 words correctly? You might be
Think you can pronounce these 10 words correctly? You might be surprised! Share Tweet Share Tagged ...
- HTML 样式兼容不同设备类型
在项目中遇到在屏幕上显示的效果和打印时显示的效果不同,可以使用media属性来指定用于不同的媒介时使用的样式. media属性值: 值 描述 screen 计算机屏幕显示(默认) tty 电传打字机以 ...
- HTTPS好文推荐
认真看完这几篇文章,HTTPS相关内容应该就能大概了解了. 1.https(ssl)协议以及wireshark抓包分析与解密 2.数字证书原理 3.也许,这样理解HTTPS更容易 4.SSL/TLS原 ...
- Linux创建SSH信任关系
Linux服务器创建信任关系可以解决远程执行命令.远程传输文件多次手工输入的麻烦.可以实现环境一键打包备份. 测试环境 SuSE 手工创建 假设服务器A与B间要建立信任关系.用户想从服务器A免密码登录 ...