My O(n) solution , runtime: 5ms
int lengthOfLongestSubstring(char *s) {\n        int m[129] = {0};\n        int i, j;\n        int cnt = 0, pre = 0;\n        int max = 0;\n        int c;\n    
    int lengthOfLongestSubstring(char *s) {\n        int m[129] = {0};\n        int i, j;\n        int cnt = 0, pre = 0;\n        int max = 0;\n        int c;\n    \n        for (i = 0; c = s[i]; i++) {\n            if (pre < m[c]) {\n                if (max < cnt)\n                    max = cnt;\n    \n                cnt = i-m[c];\n                pre = m[c];\n            }\n    \n            cnt++;\n            m[c] = i+1;\n        }\n        return max > cnt ? max : cnt;\n    }
[]