Why my level traversal solution with O(N) complexity time exceeded?

```
class Solution(object):
def connect(self, root):
"""
:type root: TreeLinkNode
:rtype: nothing
"""
q = []
if root == None:
return
q.insert(0,root)
curr = 1
next = 0
while len(q) != 0:
node = q.pop()
curr -= 1
if curr != 0:
node.right = q[-1]
if node.left != None:
q.insert(0,node.left)
next += 1
if node.right != None:
q.insert(0,node.right)
next += 1
if curr == 0:
curr = next
next = 0
```