Skip to content

Instantly share code, notes, and snippets.

@hkurokawa
Created October 5, 2014 15:33
Show Gist options
  • Save hkurokawa/029a4089a637426cb9a7 to your computer and use it in GitHub Desktop.
Save hkurokawa/029a4089a637426cb9a7 to your computer and use it in GitHub Desktop.
#include "stdio.h"
int unique_1(char* str) {
int count[256] = {0};
int i = 0;
while(1) {
char c = str[i];
if (c == '\0') return 1;
if (count[c] > 0) {
return -1;
} else {
count[c]++;
}
i++;
}
}
int unique_2(char* str) {
// Sort
}
int main(int argc, char* argv[]) {
if (argc < 2) {
fprintf(stderr, "Usage: a.out <input>\n");
return 1;
}
char* str = argv[1];
printf("Input: %s\n", str);
printf("Uniquenss: %d\n", unique_1(str));
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment