The TransCompilator

Solved LeetCode program · 684 of 1,000

#0917 · Reverse Only Letters

Easy String chunk-14.md

Original English source

Keep a shared code of 0. Keep a shared verdict of 0. Keep a shared lower as empty text. Keep a shared upper as empty text. Place "abcdefghijklmnopqrstuvwxyz" into lower. Place "ABCDEFGHIJKLMNOPQRSTUVWXYZ" into upper.

To classify. Set verdict to 0. For every spot from 0 to 25, if code is character spot of lower, set verdict to 1. For every spot from 0 to 25, if code is character spot of upper, set verdict to 1.

The source is "ab-cd". The pieces is an empty list of text.
For every spot from 0 to the last position of source.
The piece is the slice of source from spot to spot plus 1. Place piece into pieces.

The left is 0. The right is the last position of pieces.
Repeat while left is less than right.
The here is item left of pieces. The there is item right of pieces. Set code to character 0 of here. Classify. The leftok is verdict. Set code to character 0 of there. Classify. The rightok is verdict. If leftok is 1 and rightok is 1, swap item left of pieces and item right of pieces, add 1 to left, subtract 1 from right. If leftok is 0, add 1 to left. If rightok is 0, subtract 1 from right.

The answer is join pieces with "". Show answer.

Open in Playground Browse all 1,000 problems

Expected stdout

dc-ba