Find all nodes in a binary tree on a specific level (Interview Query)
问题 I mean on a specific level, NOT up to that specific level. Could someone please check my modified BFS algorithm? (most of which is taken from Wikipedia) Queue levelorder(root, levelRequested){ int currentLevel = 0; q = empty queue q.enqueue(root) while not q.empty do{ if(currentLevel==levelRequested) return q; node := q.dequeue() visit(node) if(node.left!=null || node.right!=null){ currentLevel++; if node.left ≠ null q.enqueue(node.left) if node.right ≠ null q.enqueue(node.right) } } } 回答1: I