Skip to content

Instantly share code, notes, and snippets.

@T2hhbmEK
Last active September 25, 2015 18:46
Show Gist options
  • Save T2hhbmEK/563e646eefc07003f659 to your computer and use it in GitHub Desktop.
Save T2hhbmEK/563e646eefc07003f659 to your computer and use it in GitHub Desktop.
Longest Substring Without Repeating Characters
int lengthOfLongestSubstring(char* s) {
int r, c, i, j;
int hash[256] = { 0 };
unsigned char * us = s;
if (us[0] == '\0') {
return 0;
}
r = 0;
i = 0;
j = 0;
c = 0;
while (us[j] != '\0') {
while (us[j] != '\0' && hash[us[j]] == 0x0) {
hash[us[j]] = 0x1;
c++;
j++;
}
r = c > r ? c : r;
c--;
hash[us[i]] = 0x0;
i++;
}
return r;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment