My java solution
We can see that number of empty nodes must be 1 greater than number of numeric nodes,\nand that this must only be true when we reach the end of the iteration.\n
   We can see that number of empty nodes must be 1 greater than number of numeric nodes,\nand that this must only be true when we reach the end of the iteration.\n\n\n    public boolean isValidSerialization(String s) {\n                java.util.StringTokenizer t = new  java.util.StringTokenizer(s, ",");\n                int n=0;\n                while(t.hasMoreTokens()){\n                   String st = t.nextToken();\n                   if (st.equals("#"))\n                   {\n                       if ( --n == -1 && t.hasMoreTokens()) return false;\n                   }else\n                       n++;\n                      \n                }\n                if (n==-1) return true;\n                return false;\n            }
[]