參考資訊:
https://www.cnblogs.com/grandyang/p/4480780.html
題目:
解答:
int max(int x, int y) { return (x > y) ? x : y; } int lengthOfLongestSubstring(char *s) { int r = 0; int c0 = 0; int left = -1; int hash[128] = {0}; int len = strlen(s); for (c0 = 0; c0 < 128; c0++) { hash[c0] = -1; } for (c0 = 0; c0 < len; c0++) { left = max(left, hash[s[c0]]); hash[s[c0]] = c0; r = max(r, (c0 - left)); } return r; }