C++ very simple solution, beat 67%


  • 0
    X

    class Solution {
    public:
    bool isValidSerialization(string preorder) {
    istringstream s(preorder);
    int c = 1;
    string val;
    while(getline(s, val, ','))
    {
    if(c == 0)
    return false;
    if(val == "#") c --;
    else c ++;
    }
    return c == 0;
    }
    };


Log in to reply
 

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