wfxr
10/23/2016 - 6:43 AM

Verify Preorder Serialization of a Binary Tree

Verify Preorder Serialization of a Binary Tree

Verify Preorder Serialization of a Binary Tree

bool isValidSerialization(string preorder) {
    string replaced = std::regex_replace(preorder, (regex)"\\d+,#,#", "#");
    return replaced == "#" || (replaced != preorder && isValidSerialization(replaced));
}