You solve your problem using modified BFS algorithm. When you're storing node in queue, store it's level (distance from root) as well.
確定! 回上一頁