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个,建立哈西表)的更多相关文章

  1. LeetCode longest substring without repeating characters 题解 Hash表

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

  2. 【一天一道LeetCode】 #3 Longest Substring Without Repeating Characters

    一天一道LeetCode (一)题目 Given a string, find the length of the longest substring without repeating charac ...

  3. Leetcode经典试题:Longest Substring Without Repeating Characters解析

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

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

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

  5. Leetcode:Longest Substring Without Repeating Characters 解题报告

    Longest Substring Without Repeating Characters Given a string, find the length of the longest substr ...

  6. 《LeetBook》leetcode题解(3):Longest Substring Without Repeating Characters[M]——哈希判断重复

    我现在在做一个叫<leetbook>的免费开源书项目,力求提供最易懂的中文思路,目前把解题思路都同步更新到gitbook上了,需要的同学可以去看看 书的地址:https://hk029.g ...

  7. [LeetCode]3. Longest Substring Without Repeating Characters无重复字符的最长子串

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

  8. LeetCode Longest Substring Without Repeating Characters 最长不重复子串

    题意:给一字符串,求一个子串的长度,该子串满足所有字符都不重复.字符可能包含标点之类的,不仅仅是字母.按ASCII码算,就有2^8=128个. 思路:从左到右扫每个字符,判断该字符距离上一次出现的距离 ...

  9. 【LeetCode】3 、Longest Substring Without Repeating Characters

    题目等级:Medium 题目描述:   Given a string, find the length of the longest substring without repeating chara ...

随机推荐

  1. SPring cloud (3)A Ribbon 负载均衡 配置初步

    1.引用pom <dependency> <groupId>org.springframework.cloud</groupId> <artifactId&g ...

  2. 前后台交互实现点击超链接通过指定的 url 去网络或者文件服务器下载文件

    前台 VUE 界面: <el-table-column prop="attachment" align="center" label="附件详情 ...

  3. 机器学习进阶-疲劳检测(眨眼检测) 1.dist.eculidean(计算两个点的欧式距离) 2.dlib.get_frontal_face_detector(脸部位置检测器) 3.dlib.shape_predictor(脸部特征位置检测器) 4.Orderdict(构造有序的字典)

    1.dist.eculidean(A, B) # 求出A和B点的欧式距离 参数说明:A,B表示位置信息 2.dlib.get_frontal_face_detector()表示脸部位置检测器 3.dl ...

  4. sqlserver中 事物 索引及视图

      事务 1.什么是事务 事务是一个不可分割的工作逻辑单元,它包含了一组数据库的操作命令,并且所有命令作为一个整体一起向系统提交或撤销操作请求,即要么都执行,要么都不执行 2.事务的4个属性 (1). ...

  5. svn从本地更新了资源库的资源后删除了某个文件夹无法恢复(已解决)

    事件描述: 删除了本地svn的某个文件夹中的某个文件后,想要恢复,但是无法恢复,解决方法如下 步骤: 1:在删除的文件夹下右键,选择TortoiseSVN——>Revert... 2:选择需要恢 ...

  6. NetStream 记录

    bufferLength : Number [只读] 数据当前存在于缓冲区中的秒数.(已进入缓冲区的秒数) bufferTime : Number 指定在开始显示流之前需要多长时间将消息存入缓冲区.( ...

  7. PHP对redis操作详解

    /*1.Connection*/$redis = new Redis();$redis->connect('127.0.0.1',6379,1);//短链接,本地host,端口为6379,超过1 ...

  8. ReactiveX 学习笔记(14)使用 RxJava2 + Retrofit2 调用 REST API

    JSON : Placeholder JSON : Placeholder (https://jsonplaceholder.typicode.com/) 是一个用于测试的 REST API 网站. ...

  9. js 改变颜色值

    /** * 获取颜色值 */ const color2RGB = (color) => { if (typeof color !== 'string' || (color.length !== ...

  10. Hibernate 再接触 关系映射 一对一单向外键关联

    对象之间的关系 数据库之间的关系只有外键 注意说关系的时候一定要反面也要说通 CRUD 数据库之间设计 主键关联 单向的外键关联 中间表 一对一单向外键关联 Husband.java package ...