Solved LeetCode program · 694 of 1,000
#0928 · Minimize Malware Spread II
Original English source
Keep a shared graph holding 1, 1, 0, 1, 1, 0, 0, 0, and 1. Keep a shared initial holding 0 and 1. Keep a shared infected holding 0, 0, and 0. Keep a shared candidate of 0. Keep a shared cases of 0.
To erase from spot (a whole number).
For every node from 0 to 2.
Set item node of infected to 0.
To spread from node (a whole number). If node is candidate, return. If item node of infected is 1, return. Set item node of infected to 1. The base is node times 3.
For every neighbor from 0 to 2.
If item (base plus neighbor) of graph is 1, Spread from neighbor.
To infect from spot (a whole number).
For each other in initial.
If other is not candidate, Spread from other.
To tally from spot (a whole number).
For every node from 0 to 2.
Increase cases by item node of infected.
The best is 4, while the bestnode is 0.
For every position from 0 to the last position of initial.
The cand is item position of initial. Set candidate to cand. Set cases to 0. Erase from 0. Infect from 0. Tally from 0. If cases is less than best, set best to cases, set bestnode to cand.
Show bestnode.
Expected stdout
0