The TransCompilator

Solved LeetCode program · 349 of 1,000

#0473 · Matchsticks to Square

Medium Array chunk-07.md

Original English source

Keep a shared sticks holding 1, 1, 2, 2, and 2. Keep a shared sides holding 0, 0, 0, and 0. Keep a shared squareok of 0. Keep a shared target of 0. The whole is 0.
For each stick in sticks.
Add stick to whole.

Set target to whole divided by 4. Keep a shared last of 0. The end is the last position of sticks. Set last to end.
To place from spot (a whole number). If squareok is 1, return. If spot is more than last, set squareok to 1, return. The value is item spot of sticks.
For every side from 0 to 3.
The total is item side of sides plus value.
If squareok is 0 and total is at most target.
Set item side of sides to total. Place from spot plus 1. Decrease item side of sides by value. If squareok is 1, return.

Place from 0. If squareok is 1, show true, otherwise show false.

Open in Playground Browse all 1,000 problems

Expected stdout

true