Reverse Only English Letters

STRING

Problem

Given a string s, the goal is to reverse only the English letters while maintaining the positions of all non-letter characters.

Examples

reverseOnlyLetters("Hello-World!") // "dlroW-olleH!" /* Why? Reverse the English letters to get "dlroW-olleH". The dash and the exclamation mark remain in the same positions */ reverseOnlyLetters("A1B2C3D4E5") // "E1D2C3B4A5" // Why? Only the English letters A, B, C, D, and E are reversed
Loading...