mirror of
https://github.com/donnemartin/interactive-coding-challenges
synced 2026-01-07 18:08:01 +00:00
Simplified check to determine if there are items in the queue.
This commit is contained in:
@@ -34,8 +34,6 @@
|
|||||||
"## Constraints\n",
|
"## Constraints\n",
|
||||||
"\n",
|
"\n",
|
||||||
"* Can we assume we already have a Node class with an insert method?\n",
|
"* Can we assume we already have a Node class with an insert method?\n",
|
||||||
" * Yes\n",
|
|
||||||
"* Can we use collections.deque for the queue?\n",
|
|
||||||
" * Yes"
|
" * Yes"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@@ -98,7 +96,7 @@
|
|||||||
"def bfs(root, visit_func):\n",
|
"def bfs(root, visit_func):\n",
|
||||||
" queue = deque()\n",
|
" queue = deque()\n",
|
||||||
" queue.append(root)\n",
|
" queue.append(root)\n",
|
||||||
" while len(queue) > 0:\n",
|
" while queue:\n",
|
||||||
" node = queue.popleft()\n",
|
" node = queue.popleft()\n",
|
||||||
" visit_func(node.data)\n",
|
" visit_func(node.data)\n",
|
||||||
" if node.left is not None:\n",
|
" if node.left is not None:\n",
|
||||||
|
|||||||
Reference in New Issue
Block a user