码迷,mamicode.com
首页 > 其他好文 > 详细

[LeetCode]-003-Longest Substring Without Repeating Characters

时间:2015-04-27 23:49:44      阅读:126      评论:0      收藏:0      [点我收藏+]

标签:

网址:https://leetcode.com/problems/longest-substring-without-repeating-characters/

题意:

求出最长子字符串且不含重复字符

分析:

题意比较简单

只需要注意字符串为空的特殊情况.

字符是char的0-255,不仅仅是26个小写字母.

解法:

一直统计长度,直到有字符被重复为止,再记录被重复的字符的下一位

重复该过程

比如:

abcdb

扫描到第二个b,发现前面存在b,那么start就是从第一个b的后一位算,即下标2算起.

当第一个结点发生时,长度4.

当结束后,再统计一次,长度3,比较,记录4.

理解KMP,这个题就很好解...类似于KMP的变形吧

类KMP+计数

代码:

https://github.com/LiLane/leetcode/blob/master/c%2B%2B/003-LongestSubstringWithoutRepeatingCharacters-201504232112.cpp

https://github.com/LiLane/leetcode/blob/master/java/003-LongestSubstringWithoutRepeatingCharacters-201504232111.java


[LeetCode]-003-Longest Substring Without Repeating Characters

标签:

原文地址:http://blog.csdn.net/lane_l/article/details/45317505

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!