The TransCompilator

Solved LeetCode program · 249 of 1,000

#0332 · Reconstruct Itinerary

Hard Array chunk-05.md

Original English source

Keep a shared starts as an empty list of text. Keep a shared finishes as an empty list of text. Keep a shared used holding 0, 0, 0, and 0. Keep a shared route as an empty list of text. Keep a shared winner as an empty list of text. Keep a shared found of 0. Place "MUC" into starts. Place "JFK" into starts. Place "SFO" into starts. Place "LHR" into starts. Place "LHR" into finishes. Place "MUC" into finishes. Place "SJC" into finishes. Place "SFO" into finishes.

To save from spot (a whole number). If spot is more than the last position of route, return. Place item spot of route into winner. Save from spot plus 1.

To seek from depth (a whole number). If found is 1, return. If depth is 4, set found to 1. If depth is 4, save from 0. If depth is 4, return.
For every spot from 0 to 3.
If found is 1, stop. The origin is item spot of starts. The arrival is item spot of finishes. The same is 1. If origin comes before item depth of route, set same to 0. If item depth of route comes before origin, set same to 0. The hit is 0. If item spot of used is 0 and same is 1, set hit to 1. If hit is 1, set item spot of used to 1. If hit is 1, Place arrival into route. If hit is 1, seek from depth plus 1. If hit is 1, remove the last item from route. If hit is 1, set item spot of used to 0.

Place "JFK" into route. Seek from 0. The answers is join winner with ",". The parts is split answers by ",". For each part in parts, show part.

Open in Playground Browse all 1,000 problems

Expected stdout

JFK
MUC
LHR
SFO
SJC