Question 1 Minimum Moves to Spread Stones Over Grid
Method 4 Bi-Directional BFS
class BFSIterator {
// 功能: next() hasNext()
private Deque<Node> queue;
private Map<Node, Integer> visited; // 每个点,从起点出发到这个点的最短路径
public BFSIterator(Node init) {
this.queue = new LinkedList<>();
this.visited = new HashMap<>();
queue.offer(init);
visited.put(init, 0);
}
}Last updated