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.

找到不包含重复字母的最长字符串

解题思路:

1.用双指针i,j;其中j往后遍历,thiscount++,当遇到重复的字符时候,j停下

2.用BitMap保存已经遍历过的字符

3.当j停下时候,i往后遍历至重复字符第一次出现的值后面,同时thiscout--

 int lengthOfLongestSubstring(char* s) {
int i=,j=;
int flag[]={};  //创建BitMap
int c;
int count=,thiscount=;
while(s[j])
{
c=s[j];
if(!(flag[c>>]&(<<(c&0x1f)))) //当此字符不重复时
{
flag[c>>]|=(<<(c&0x1f));   //标记字符
thiscount++;
if(thiscount>count)
count=thiscount;
}
else
{
while(s[i]!=s[j])
{
c=s[i];
flag[c>>]^=(<<(c&0x1f));  //把重复字符及其第一次出现位置之前的字符从BitMap中删除
thiscount--;
i++;
}
i++;
}
j++;
}
return count;
}

【LeetCode】3. Longest Substring Without Repeating Characters的更多相关文章

  1. 【LeetCode】3. Longest Substring Without Repeating Characters 无重复字符的最长子串

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 公众号:负雪明烛 本文关键词:无重复字符,最长子串,题解,leetcode, 力扣,py ...

  2. 【LeetCode】3.Longest Substring Without Repeating Characters 最长无重复子串

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

  3. 【LeetCode】3. Longest Substring Without Repeating Characters (2 solutions)

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

  4. 【LeetCode】003. Longest Substring Without Repeating Characters

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

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

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

  6. leetcode-【中等题】3. Longest Substring Without Repeating Characters

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

  7. leetcode题解 3. Longest Substring Without Repeating Characters

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

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

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

  9. LeetCode OJ:Longest Substring Without Repeating Characters(最长无重复字符子串)

    Given a string, find the length of the longest substring without repeating characters. For example, ...

随机推荐

  1. SQL sever 创建定时执行任务

    在SQL的使用过程中,我们经常要做些数据备份以及定时执行的任务. 这些任务能够帮助我们简化工作过程. 下面我们了解下如何创建一个定时执行的存储过程. 首先我们要打开 SQL server 代理服务 选 ...

  2. svn 目录设置为 不提交 忽略

    svn 忽略  以下文件 和目录 (不提交) runningtime --选中 tortoiseSVN --unversion and add to ignore list web workspace ...

  3. 继承,多态,集合,面向对象,XML文件解析,TreeView动态加载综合练习----->网络电视精灵项目练习、分析

    网络电视精灵 项目运行状态如图: 项目完成后的类: 首先,将程序分为二部分进行: 一:TreeView节点内容的设计及编写: 1.1遍写XML文件:管理(FullChannels.xml),A类电视台 ...

  4. Logstash利用GeoIP库显示地图以及通过useragent显示浏览器(四)

    我们通过Logstash收集的Nginx Access log中已经包含了客户端IP的数据(remote_addr),但是只有这个IP还不够,要在Kibana的显示请求来源的地理位置还需要借助GeoI ...

  5. 手机端rem自适应布局实例

    首先要书写核心js代码,控制住页面的初始大小:我是以750px(即iPhone6)的标准,设置font-size:100px:<script>        (function (doc, ...

  6. 工厂模式Assembly.Load(path).CreateInstance 反射出错解决办法

    项目结构: DALFactory 反射代码反射 //使用缓存 private static object CreateObject(string AssemblyPath,string classNa ...

  7. android相关内容

    一: 前台进程: 前台的进程的优先级最高, 可见进程: android系统一般存在少量的可见进程. 服务进程: 没有用户界面, 后台进程: 一般存在较多的后台进程. 空进程: 不包括任何活跃组件的进程 ...

  8. [河南省ACM省赛-第三届] 房间安排 (nyoj 168)

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=168 分析:找到一天中需要最多的房间即可 #include<iostream> ...

  9. C#泛型委托及约束

    泛型委托: namespace 泛型委托 { public delegate void Mydelegate<T>(T msg); class Program { static void ...

  10. 关于git提交、还原使用

    1.本地修改,未提交到本地仓库,想要恢复到修改前 右键这个文件-team-show local hostory -找到某一版本-右键-get Contents 即可恢复到某一版本 2. 命令:git ...