[LeetCode]-003-Longest Substring Without Repeating Characters
2015-04-27 22:24
429 查看
网址: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
题意:
求出最长子字符串且不含重复字符
分析:
题意比较简单
只需要注意字符串为空的特殊情况.
字符是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
相关文章推荐
- Leetcode003 Longest Substring Without Repeating Characters
- leetcode_c++:哈希:Longest Substring Without Repeating Characters(003)
- [LeetCode]题解(python):003-Longest Substring Without Repeating Characters
- 2017-09-07 LeetCode_003 Longest Substring Without Repeating Characters
- [LeetCode 003] Longest Substring Without Repeating Characters
- leetcode 003 Longest Substring Without Repeating Characters
- 【LeetCode】003 Longest Substring Without Repeating Characters 最长的没有重复的子字符串
- leetcode解题方案--003--LongestSubstringWithoutRepeatingCharacters
- LeetCode 003 Longest Substring Without Repeating Characters
- Leetcode_003_Longest_Substring_Without_Repeating_Characters
- [LeetCode]003-Longest Substring Without Repeating Characters
- 003 Longest Substring Without Repeating Characters [Leetcode]
- LeetCode - Longest SubString without repeating characters_003
- LeetCode 003-Longest Substring Without Repeating Characters
- LeetCode-003 Longest Substring Without Repeating Characters
- LeetCode003__Longest Substring Without Repeating Characters
- leetcode 003 Longest Substring Without Repeating Characters(java)
- 【leetcode】003 Longest Substring Without Repeating Characters
- 【JAVA、C++】LeetCode 003 Longest Substring Without Repeating Characters
- LeetCode 003 Longest Substring Without Repeating Characters