Skip to main content
added 10 characters in body
Source Link
coderodde
  • 32.1k
  • 15
  • 78
  • 205

I have only a couple of nitpicks:

Nitpick 1

while len(queue) > 0:

You can write just as:

while queue:

Nitpick 2

Instead of a (list) queue, you need a deque:

from collections import deque

This stems from the fact that list's pop(0) (as in @harold's answer) runs in \$\Theta(n)\$ time; with a deque you can do the same in \$\mathcal{O}(1)\$ (try it).

I have only a couple of nitpicks:

Nitpick 1

while len(queue) > 0:

You can write just as:

while queue:

Nitpick 2

Instead of a (list) queue, you need a deque:

from collections import deque

This stems from the fact that list's pop(0) (as in @harold's answer) runs in \$\Theta(n)\$ time; with a deque you can do the same in \$\mathcal{O}(1)\$

I have only a couple of nitpicks:

Nitpick 1

while len(queue) > 0:

You can write just as:

while queue:

Nitpick 2

Instead of a (list) queue, you need a deque:

from collections import deque

This stems from the fact that list's pop(0) (as in @harold's answer) runs in \$\Theta(n)\$ time; with a deque you can do the same in \$\mathcal{O}(1)\$ (try it).

Source Link
coderodde
  • 32.1k
  • 15
  • 78
  • 205

I have only a couple of nitpicks:

Nitpick 1

while len(queue) > 0:

You can write just as:

while queue:

Nitpick 2

Instead of a (list) queue, you need a deque:

from collections import deque

This stems from the fact that list's pop(0) (as in @harold's answer) runs in \$\Theta(n)\$ time; with a deque you can do the same in \$\mathcal{O}(1)\$