class Solution {
public String reversePrefix(String word, char ch) {
int k = word.indexOf(String.valueOf(ch));
if(k == 0 || k == -1) return word;
char[] result = word.toCharArray();
for(int i = 0; i <= k/2; i++){
char temp = result[i];
result[i] = result[k - i];
result[k - i] = temp;
}
return new String(result);
}
}
2000.反转单词前缀0ms
最新推荐文章于 2024-11-08 15:35:46 发布