Last active
September 25, 2015 18:46
-
-
Save T2hhbmEK/563e646eefc07003f659 to your computer and use it in GitHub Desktop.
Longest Substring Without Repeating Characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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