weird errors python solution: suspect leetcode issue

  • 0

    The code cannot even pass

    but if I use "run code":

    Your input

    Your stdout

    0 1
    Your answer

    Expected answer

    Show Diff

    # Definition for a binary tree node.
    # class TreeNode(object):
    #     def __init__(self, x):
    #         self.val = x
    #         self.left = None
    #         self.right = None
    idx = 0
    class Codec:
        def serialize(self, root):
            """Encodes a tree to a single string.
            :type root: TreeNode
            :rtype: str
            if not root: return ""
            stk = [root]
            ret = []
            while stk:
                cur = stk.pop()
                if cur.right:
                if cur.left:
            return ','.join(ret)
        def deserialize(self, data):
            """Decodes your encoded data to tree.
            :type data: str
            :rtype: TreeNode
            def helper(data, minv, maxv):
                global idx
                if idx>=len(data) or data[idx]<minv or data[idx]>maxv:
                    return None
                root = TreeNode(int(data[idx]))
                root.left = helper(data, minv, root.val)
                root.right = helper(data, root.val, maxv)
                print root.val, idx
                return root
            if not data:
                return None
            data = data.split(',')
            data = [int(d) for d in data]
            return helper(data, -sys.maxint-1, sys.maxint)
    # Your Codec object will be instantiated and called as such:
    # codec = Codec()
    # codec.deserialize(codec.serialize(root))

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.