link Knight Dialer Thought Since it ask how many distinct numbers could be generated, DP jumps to my mind immediately. Firstly, the relation is, if knight stop at number 6, it has to come from 1, 7, or 0. So I keep a DP array, DP[j][i] stands for how many unique numbers it could generate […]

Read More → 935 Knight Dialer

link: Shortest Bridge Thought Since the question ask for shortest, so BFS probabely the best algorithms to solve it. But notice, I will use 2 bfs funciton, one to find the edge of first island, the other one is to reach another island based on first edge. BFS1: input: start positionstop condition: queue emptygenerate & […]

Read More → 934 Shortest Bridge