Solved LeetCode program · 406 of 1,000
#0547 · Number of Provinces
Original English source
Keep a shared links holding 1, 1, 0, 1, 1, 0, 0, 0, and 1. Keep a shared visited as an empty list of whole numbers.
For every city from 0 to 2.
Place 0 into visited.
Keep a shared size of 3.
To walk from city (a whole number). If item city of visited is 1, return. Set item city of visited to 1.
For every next from 0 to 2.
The spot is city times size plus next. If item spot of links is 1, walk from next.
The provinces is 0.
For every city from 0 to 2.
If item city of visited is 0, add 1 to provinces. If item city of visited is 0, walk from city.
Show provinces.
Expected stdout
2