6 lines Python, 7 lines Java
Python\n\n    def isValidSerialization(self, preorder):\n        need = 1\n        for val in preorder.split(','):\n            if not need:\n                re
**Python**\n\n    def isValidSerialization(self, preorder):\n        need = 1\n        for val in preorder.split(','):\n            if not need:\n                return False\n            need -= ' #'.find(val)\n        return not need\n\n**Java**\n\n    public boolean isValidSerialization(String preorder) {\n        int need = 1;\n        for (String val : preorder.split(",")) {\n            if (need == 0)\n                return false;\n            need -= " #".indexOf(val);\n        }\n        return need == 0;\n    }
['Python', 'Java']