I can't figure why my code exceeds the time limit.

It'd be great help if someone could point out the bug

```
# Definition for a binary tree node
# class TreeNode:
# def __init__(self, x):
# self.val = x
# self.left = None
# self.right = None
class Solution:
# @param root, a tree node
# @return nothing, do it in place
def preorder(self,root,a):
if root == None:
return
a.append(root)
self.preorder(root.left,a)
self.preorder(root.right,a)
def flatten(self, root):
a = []
self.preorder(root,a)
if not root == None:
while len(a) > 0:
root.left = None
root.right = a.pop(0)
root = root.right
```