Longest Substring Without Repeating Characters – LeetCode

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.

Solution

The approach is to scan the string from left one by one. If a duplicate character is found and its recent position is greater than the start position, then adjust the start position.

Time complexity: O(n)
Space: O(1)

Example:
Longest_Substring_Without_Repeating_Characters

Code example:

or using an Array to record character position

Challenge: can you solve this problem?
Longest Palindromic Substring – LeetCode

Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedInShare on RedditShare on StumbleUponEmail this to someoneShare on TumblrDigg this

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">