Returns the maximum substring of a string that does not contain repeated characters.

Source: Internet
Author: User

This question was encountered during the last interview, and the computation was complete.CodeImplement it.

When judging the cyclic conditions, I made a low-level error in judging whether equal null was not referenced by the pointer. It must have been a fever for the past two days...

Write a little code every day and make a little progress every day. Come on ~

# Include <string. h> # include <stdio. h> # include <stdlib. h> bool contains (char * STR, char * value, int num) {If (* STR = NULL | * value = NULL) {printf ("Please check the parameters \ n"); Return true ;}for (; num> 0; ++ STR, -- num) {If (* Str) = (* value) return true;} return false;} void max_substring (char * DEST, char * & Pret, Int & COUNT) {pret = NULL; Count = 0; char * pstart = DEST, * pend, * pcurrent; I NT tmpcount = 0; while (* pstart! = NULL) {pcurrent = pstart; pend = pcurrent + 1; tmpcount = 1; while (* pend! = NULL &&! Contains (pcurrent, pend, tmpcount) {++ pend; ++ tmpcount;} If (tmpcount> count) {COUNT = tmpcount; pret = pcurrent ;} if (* pend = NULL) return; ++ pstart ;}} int main () {char Tom [] = "Hello World"; char * tmpj; int count; printf ("the original string is % s \ n function is used to find its largest non-duplicate substring \ n", Tom); max_substring (Tom, tmpj, count ); char result [sizeof (Tom)]; strncpy (result, tmpj, count); Result [count] = NULL; printf ("count is % d, and the string is % s \ n ", Count, result); System (" pause "); Return 0 ;}

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.