Clear c++ solution


  • 12
    V
    bool isValidSerialization(string preorder) {
    	int degree = 1;
    	string temp;
    	stringstream ss;
    	ss << preorder;
    	while (getline(ss, temp, ',')) {
    		degree--;
    		if (degree < 0)
    			return false;
    		if (temp[0] != '#')
    			degree += 2;
    	}
    	return degree == 0;
    }

Log in to reply
 

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