Skip to content

Instantly share code, notes, and snippets.

@JasonGitHub
Last active December 13, 2015 21:08
Show Gist options
  • Select an option

  • Save JasonGitHub/4975307 to your computer and use it in GitHub Desktop.

Select an option

Save JasonGitHub/4975307 to your computer and use it in GitHub Desktop.
//Time: n^2 Space: 0
void RemoveDuplicate(char* str) {
char* tail = str;
char* p1 = str;
char* p2 = str;
while (*p2 != '\0') {
for (p1 = str; p1 < tail; ++p1) {
if (*p2 == *p1) break;
}
if (p1 == tail) *(tail++) = *p2;
++p2;
}
*tail = *p2;
}
//Time: n Space: 256
void RemoveDuplicate1(char* str) {
bitset<256> hit;
char* tail = str;
while (*str != '\0') {
if (!hit[*str]) {
hit[*str] = true;
*tail = *str;
++tail;
}
++str;
}
*tail = '\0';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment