easiest begginer frinedly O(1) space c++ solution
Here\'s how the function works:\n\nInitialize a variable val to 1. This represents the number of nodes in the binary tree that have not yet been processed.\n\nI
Here\'s how the function works:\n\nInitialize a variable val to 1. This represents the number of nodes in the binary tree that have not yet been processed.\n\nIterate over the characters in the string nums. For each character:\n\na. If the character is a comma, skip it and continue to the next character.\n\nb. If the character is a \'#\' (representing a null node), decrement val by 1.\n\nc. If the character is not a \'#\' (representing a non-null node), decrement val by 1 and increment it by 2 (to account for the two child nodes that a non-null node has). Also, skip over the rest of the characters representing the current node\'s value and its children (up to the next comma).\n\nd. If val becomes negative at any point, return false (because the tree is invalid).\n\nAfter processing all characters in the string, if val is equal to 0, return true (because the tree is valid). Otherwise, return false (because the tree is invalid\n\n```\nclass Solution {\npublic:\n    bool isValidSerialization(string nums) {\n        int val = 1;\n        for (int i = 0; i < nums.length(); i++) {\n            if (nums[i] == \',\') {\n                continue;\n            }\n            val--;\n            if (val < 0) {\n                return false;\n            }\n            if (nums[i] != \'#\') {\n                val += 2;\n                while (i + 1 < nums.length() && nums[i+1] != \',\') {\n                    i++;\n                }\n            }\n        }\n        return val == 0;\n    }\n};\n```\n\n\nSb answer pdh k chle jaate hai , koi upvote nhi krta
[]