Wednesday, September 24, 2014

Longest Substring Without Repeating Characters

Problem

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.

Idea

用个数组pos[]记录每个字符上次出现的位置,然后用start记录子串的起始,当pos[s[i]] >= start时表明重复,则计算长度,知道最后一个子串
输入数据可能存在除了英文字母以外的数据

Solution


No comments:

Post a Comment