File tree 1 file changed +1
-27
lines changed
src/main/java/com/fishercoder/solutions
1 file changed +1
-27
lines changed Original file line number Diff line number Diff line change 1
1
package com .fishercoder .solutions ;
2
2
3
- /**
4
- * 917. Reverse Only Letters
5
- *
6
- * Given a string S, return the "reversed" string where all characters
7
- * that are not a letter stay in the same place, and all letters reverse their positions.
8
- *
9
- * Example 1:
10
- *
11
- * Input: "ab-cd"
12
- * Output: "dc-ba"
13
- * Example 2:
14
- *
15
- * Input: "a-bC-dEf-ghIj"
16
- * Output: "j-Ih-gfE-dCba"
17
- * Example 3:
18
- *
19
- * Input: "Test1ng-Leet=code-Q!"
20
- * Output: "Qedo1ct-eeLg=ntse-T!"
21
- *
22
- *
23
- * Note:
24
- *
25
- * S.length <= 100
26
- * 33 <= S[i].ASCIIcode <= 122
27
- * S doesn't contain \ or "
28
- * */
29
3
public class _917 {
30
4
public static class Solution1 {
31
5
public String reverseOnlyLetters (String S ) {
32
6
char [] array = S .toCharArray ();
33
- for (int i = 0 , j = array .length - 1 ; i < j ;) {
7
+ for (int i = 0 , j = array .length - 1 ; i < j ; ) {
34
8
if (Character .isLetter (array [i ]) && Character .isLetter (array [j ])) {
35
9
char temp = array [i ];
36
10
array [i ++] = array [j ];
You can’t perform that action at this time.
0 commit comments