004 String weight (keep it up)

Source: Internet
Author: User

The algorithm is designed and the code is written out to remove the repeated characters in the string, and no additional cache space is used.

Note: The ability to use an additional one or two variables, but does not agree to open an additional array copy.

Simple question directly on the code:

#include <stdio.h> #include <string.h>void remove_duplicate (char vstr[]) {int Len = strlen (VSTR); Len) {printf ("The string is Null\n"); return;}    int Count = 0;for (int i=0; i<len; ++i) {if (vstr[i]! = ' + ') {vstr[count++] = vstr[i];for (int k=i+1; k<len; ++k) {if (Vstr[i] = = Vstr[k]) {vstr[k] = '% ';}}}} Vstr[count] = ' + ';} void Remove_duplicate2 (char vstr[]) {int Len = strlen (VSTR); Len) {printf ("The string is Null\n"); return;} BOOL Visited[256];memset (visited, 0, sizeof (visited)), int Count = 0;for (int i=0; i<len; ++i) {if (! Visited[vstr[i]]) {vstr[count++] = Vstr[i]; Visited[vstr[i]] = true;}} Vstr[count] = ' + ';} void Test () {char str[] = "13434343435568889HHHHHHHFDCVBB"; remove_duplicate (str);p rintf ("%s\n", str);}

Keep it up those write several algorithms per week, entertainment!

Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.

004 String weight (keep it up)

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.