leetcode-14-basic-breadthFirstSearch BFS: breadth first search 107. Binary Tree Level Order Traversal II 解题思路: 本来我是用map<int,int>存所有节点的值和深度(root是0),然后遍历map,result[depth].push_back(val)。但是因为map是无序的,所以 插入的时候,result[i]里元素的顺序会有问题,比如 后面改...
a queue stores [step0, step1, step2, ...] queue.add(first step) while queue is not empty current_step = queue.poll() // do something here with current_step // like counting foreah step in current_step can jump to queue.add(step) 代码1:通过统计每一行的结点数: publicList<List<Int...
Employee 1 has importance value 5, and he has two direct subordinates: employee 2 and employee 3. They both have importance value 3. So the total importance value of employee 1 is 5 + 3 + 3 = 11. Note: One employee has at most one direct leader and may have several subordinates. Th...
Knight Shortest Path(Lintcode 611) Description English Given a knight in a chessboard (a binary matrix with0as empty and1as barrier) with asourceposition, find the shortest path to adestinationposition, return the length of the route. Return-1if destination cannot be reached. source and destin...
今天的笔记包含基于树的宽度优先搜索(Tree Breadth-First Search)类型下的5个题目,它们在leetcode上的编号和题名分别是: 102 - Binary Tree Level Order Traversal 107 - Binary Tree Level Order Traversal II 103 - Binary Tree Zigzag Level Order Traversal 199 - Binary Tree Right Side View 111 - Minimum...