classSolution { publicbooleanisValidSerialization(String s) { String[] ss = s.split(","); intn= ss.length; intin=0, out = 0; for (inti=0; i < n; ++i) { if (!ss[i].equals("#")) out += 2; if (i != 0) ++in; if (i != n - 1 && out <= in) returnfalse; } return in == out; } }