MCPcopy Create free account
hub / github.com/Tiwarishashwat/InterviewCodes / reverseOnlyLetters

Method reverseOnlyLetters

ReverseOnlyLetters.java:2–21  ·  view source on GitHub ↗
(String s)

Source from the content-addressed store, hash-verified

1class Solution {
2 public String reverseOnlyLetters(String s) {
3 char arr[] = s.toCharArray();
4 int start=0,end=arr.length-1;
5
6 while(start<end)
7 {
8 if(!Character.isLetter(arr[start])) start++;
9 else if(!Character.isLetter(arr[end])) end--;
10 else
11 {
12 char p = arr[start];
13 arr[start] = arr[end];
14 arr[end] = p;
15 start++;
16 end--;
17 }
18 }
19 return String.valueOf(arr);
20
21 }
22}
23

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected