My 4ms C solution in 8 lines


  • 0
    M
    int lengthOfLongestSubstring(char* s) {
        int longest = 0, currentLength = 0, start = 0, position[128] = {0};
        for(int i = 0; s[i]; position[s[i]] = ++i, currentLength++) {
            if(position[s[i]] > start) {
                longest = (longest > currentLength) ? longest : currentLength;
                start = position[s[i]];
                currentLength = i - position[s[i]];}}
        return (longest > currentLength) ? longest : currentLength;}

  • 0
    S

    What's the point squeezing all braces in one line?


  • 0
    M

    It's called lisp style or python style. It looks like python and it has no uninformative lines.

    https://en.wikipedia.org/wiki/Indent_style


  • 0
    3

    i test the code,but the result is 1.why this code can be accepted.....


  • 0
    W

    it takes some time to understand, thanks


Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.