1
class Solution {
2
public String reversePrefix(String word, char ch) {
3
char[] c = word.toCharArray();
4
int locate = 0;
5
for (int i = 0; i < word.length(); i++) { // first occurrence of ch
6
if (ch == c[i]) {
7
locate = i;
8
break;
9
}
10
}
11
char[] res = new char[word.length()];
12
for (int i = 0; i <= locate; i++) {
13
res[i] = c[locate - i];
14
}
15
for (int i = locate + 1; i < word.length(); i++) {
16
res[i] = c[i];
17
}
18
return String.valueOf(res);
19
}
20
}

0

WPM •0 •0

100%

ACC •0 •0

0s

TIME •0