We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Try 2: Bug Free
from collections import deque class Codec: def serialize(self, root): if not root: return "" res = [] queue = deque([root]) while queue: node = queue.popleft() if node: res.append(str(node.val)) queue.append(node.left) queue.append(node.right) else: res.append("x") return ",".join(res) def deserialize(self, data): if not data: return None nums = data.split(",") root = TreeNode(nums[0]) queue = deque([root]) index = 0 while queue: node = queue.popleft() index += 1 if nums[index] != "x": node.left = TreeNode(int(nums[index])) queue.append(node.left) index += 1 if nums[index] != "x": node.right = TreeNode(int(nums[index])) queue.append(node.right) return root
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Try 2: Bug Free
The text was updated successfully, but these errors were encountered: