C++ 2 lines RegEx Solution Base on @angrybirdRR and @StefanPochmann's Discussion


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

Log in to reply
 

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