- Making A Large Island
Input: A 2D Integer grid
Output: the largest island when you change one 0 to 1
Limit: can only change one 0 to 1
如何确定largest island?
暴力搜:每一个点都改一次
优化的方向: 找到较大的两个Component 之间的链接通路
被1包围的0 ? 求最值类的问题模板?
跳过
- Open the Lock
起点0000, 终点target, 中间的路径有死路
Limit: deadends + 一次变换一个数字
问题:每变一个数字就查一次deadends?
可以变的数组与实际变的数字, 最短路径问题
九章参考答案梳理:
Hashset 存所有的deadends 字符串,同时check当前start是否是deadend
声明一个queue结构和另一个新的hashset结构,向队列和hashset当中分别添加start
单独声明set是为了防止重复,优化代码的效率?
两个while循环,一个while是对所有的queue,内部的while是对于当前层的字符做遍历,
- Network Delay Time
模板题目
times[i] = (u, v, w), u是起点,v是终点,w是发送的时间
single source all destinations shortest path
Dijkstra's algorithm
Bellman-Ford
Floyd-Warshall
对于Comparator的理解
PriorityQueue需要声明类型 PriorityQueue
-
Is Graph Bipartite
Bipartite graphs
A bipartite graph consists of sets of vertices X and Y -
Pacific Atlantic Water Flow