9 lines 0ms easy C solution


  • 0
    U
    bool isValidSerialization(char* preorder) {
        int i = 0, j = 0;
        char l = ',';
        for (; *preorder; l = *preorder, ++preorder){
            if (*preorder == '#') ++j;
            else if (*preorder == ',') ;
            else if (l == ',' || l == '#') ++i;
            if (j - 1 == i) break;
        }   
        return j - 1 == i && *preorder && !*(preorder + 1) ? true : false;
    }
    

Log in to reply
 

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