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. VMware设置cpu虚拟化,intel VT-x

    1.关闭虚拟机 2.右键需要更改的虚拟机--设置--处理器

  2. php实现单点登录,顶级域名与子域名间共享Cookie实现单点登录原理

    这是一个简单版的php单点登录概述,如果需要实现复杂的需自己,编写复杂的ticket加解密算法. 先看张图. sso系统,http://sso.yxh.com 1 2 3 4 5 <?php   ...

  3. react-native android 权限问题

    初入reactNative 的一个坑 我是用的真机测试,没用安卓模拟器 第一次在安卓上打开应用,提示权限问题: Overlay permissions needs to be granted in o ...

  4. jsfl 常用自定义方法

    //创建文件夹 function creatFile(fileURl) { if (FLfile.createFolder(fileURl)) { //alert("创建成功 "+ ...

  5. SpringBoot配置发送邮件

    一.导入jar包 <dependency> <groupId>org.springframework.boot</groupId> <artifactId&g ...

  6. ajax之发送post请求

    jquery发送post请求 function AjaxSubmit3() { //jquery发送post请求 $.ajax({ url: '/app04/ajax1/', type: 'POST' ...

  7. TCP连接异常断开检测(转)

    TCP是一种面向连接的协议,连接的建立和断开需要通过收发相应的分节来实现.某些时候,由于网络的故障或是一方主机的突然崩溃而另一方无法检测到,以致始终保持着不存在的连接.下面介绍一种方法来检测这种异常断 ...

  8. oracle归档日志关闭和打开

    查询归档日志状态 方法一 SQL> archive log list; 方法二 SQL> select name,log_mode from V$database; 打开归档日志 orac ...

  9. C++几个重要关键字(包含借鉴其他博主的东西)

    //内存 栈区 与 static区 ,C++为了兼容C,#include 只是文本替换,导致一堆命名空间之间的复杂问题,倍受人诟病 extern  关键字 1.基本含义:意如其名,告诉编译器声明的东西 ...

  10. 利用官方的vue-cli脚手架来搭建Vue集成开发环境

    在利用vue-cli脚手架搭建vue集成环境之前,我们需要先安装nodejs的环境.如果在cmd中输入node --version和npm --version出现如下的版本信息,就说明安装已经成功了. ...