Solved LeetCode program · 71 of 1,000
#0071 · Simplify Path
Original English source
The path is empty text. Place "/home//foo/" into path. The parts is split path by "/". The stack is an empty list of text.
For each part in parts.
If part is "", skip to the next one. If part is ".", skip to the next one. The size is the number of items in stack. The parentstep is 0. If part is "..", set parentstep to 1. If parentstep is 1 and size is more than 0, remove the last item from stack. If parentstep is 1 and size is 0, skip to the next one. The keep is 1. If part is "", set keep to 0. If part is ".", set keep to 0. If parentstep is 1, set keep to 0. If keep is 1, Place part into stack.
The joined is join stack with "/". The result is empty text. Place "/" into result. Place joined into result. Report result.
Expected stdout
/home/foo