Longest string with no repeating characters

Source: Internet
Author: User

Title Description:

Given a string, find the length of the oldest string that does not contain repeating characters.  Example:    given "ABCABCBB", the oldest string without repeating characters is "abc", then the length is 3.  given "bbbbb", the longest substring is "B" and the length is 1.  given "Pwwkew", the oldest string is "Wke" and the length is 3. Note that the answer must be a substring, "Pwke" is a subsequence  rather than a substring
Assuming the string is 0, return 0
Traversing a string, first judging whether the character is in the string TC, not, adding, and recording the length of the string
If in, add the character to the string TC and intercept from the place where the character occurred

ClassSolution:deflengthoflongestsubstring (self, s): M=0 TC=str () forCinchS:ifC not inchTC:TC+=C M=Max (LEN (TC), M)Else: TC+=C TC=tc[tc.index (c) + 1:] returnM

Longest string with no repeating characters

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.