Class Solution

java.lang.Object
g0901_1000.s0917_reverse_only_letters.Solution

public class Solution extends Object
917 - Reverse Only Letters.<p>Easy</p> <p>Given a string <code>s</code>, reverse the string according to the following rules:</p> <ul> <li>All the characters that are not English letters remain in the same position.</li> <li>All the English letters (lowercase or uppercase) should be reversed.</li> </ul> <p>Return <code>s</code> <em>after reversing it</em>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> s = &ldquo;ab-cd&rdquo;</p> <p><strong>Output:</strong> &ldquo;dc-ba&rdquo;</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> s = &ldquo;a-bC-dEf-ghIj&rdquo;</p> <p><strong>Output:</strong> &ldquo;j-Ih-gfE-dCba&rdquo;</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> s = &ldquo;Test1ng-Leet=code-Q!&rdquo;</p> <p><strong>Output:</strong> &ldquo;Qedo1ct-eeLg=ntse-T!&rdquo;</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= s.length <= 100</code></li> <li><code>s</code> consists of characters with ASCII values in the range <code>[33, 122]</code>.</li> <li><code>s</code> does not contain <code>'\&quot;'</code> or <code>'\\'</code>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • reverseOnlyLetters

      public String reverseOnlyLetters(String s)