BFS有固定的套路 类似下面这个形式
ArrayList<String> queue = new ArrayList<String>(); queue.add(root); while(!queue.isEmpty()) { String temp = queue.poll(); for(neigbor : temp) { queue.add(); } }
时间: 2024-08-10 02:00:12
BFS有固定的套路 类似下面这个形式
ArrayList<String> queue = new ArrayList<String>(); queue.add(root); while(!queue.isEmpty()) { String temp = queue.poll(); for(neigbor : temp) { queue.add(); } }