The TransCompilator

Solved LeetCode program · 31 of 1,000

#0031 · Next Permutation

Medium Array chunk-01.md

Original English source

The nums is a list of 1, 2, and 3. The last is the last position of nums. The pivot is -1. The position is last minus 1.
Repeat while position is at least 0.
If item position of nums is less than item (position plus 1) of nums, set pivot to position, break. Set position to one less than position.

The mark is last.
If pivot is at least 0.
Repeat while item mark of nums is at most item pivot of nums.
Set mark to one less than mark.

If pivot is at least 0, swap item pivot of nums and item mark of nums. The left is pivot plus 1. The right is last.
Repeat while left is less than right.
Swap item left of nums and item right of nums. Add 1 to left. Subtract 1 from right.

For each value in nums, display value.

Open in Playground Browse all 1,000 problems

Expected stdout

1
3
2