Easy to Understand Java Solution 3ms
we just keep the count of number of nodes we need. For the root node we need 2 child node and after that for every non-null node we add 2 child node in nodeCoun
we just keep the count of number of nodes we need. For the root node we need 2 child node and after that for every non-null node we add 2 child node in nodeCounter and decrese one node in NodeCounter. And for every null node we decreases nodeCounter. At last if nodeCounter is 0 than it is valid and at any time in the loop if nodecounter is become zero then we return false.\n```\nclass Solution {\n    public boolean isValidSerialization(String s) {\n        int node=0;\n        String[] ar = s.split(",");\n        int n=ar.length;\n        \n        int i=0;\n        if(n==0)\n            return true;\n        if(ar[0].charAt(0)!=\'#\')\n            node=2;\n        i=1;\n        while(i<n){\n            if(node==0)\n                return false;\n            \n            if(ar[i].charAt(0)!=\'#\'){\n                node++;\n            }else{\n                node--;\n            }\n            i++;\n        }\n        if(node==0)\n            return true;\n        else\n            return false;\n    }\n}\n```\n\n
['Java']