Solved LeetCode program · 712 of 1,000
#0947 · Most Stones Removed with Same Row or Column
Original English source
Keep a shared columns holding 0, 0, 1, 1, 2, and 2. Keep a shared rows holding 0, 1, 0, 2, 1, and 2. Keep a shared parents as an empty list of whole numbers. Keep a shared chief of 0.
To locate from stone (a whole number). If item stone of parents is stone, set chief to stone, return. The up is item stone of parents. Locate from up. Set item stone of parents to item up of parents.
To attach from first (a whole number) with second (a whole number). Locate from first. The one is chief. Locate from second. The two is chief. If one is not two, set item one of parents to two.
To pair from first (a whole number).
For every second from first plus 1 to the last position of parents.
If item first of columns is item second of columns or item first of rows is item second of rows, attach from first with second.
For every stone from 0 to the last position of columns.
Place stone into parents.
For every first from 0 to the last position of parents.
Pair from first.
The roots is 0.
For every stone from 0 to the last position of parents.
If item stone of parents is stone, add 1 to roots.
The final stone is the last position of columns. The total is final stone plus 1. The answer is total minus roots. Show answer.
Expected stdout
5