Reverse
Example 1:
Input:
"Let's take LeetCode contest"
Output:
"s'teL ekat edoCteeL tsetnoc"class Solution {
public String reverseWords(String s) {
String[] str = s.split(" ");
for (int i = 0; i < str.length; i++) {
str[i] = new StringBuilder(str[i]).reverse().toString();
}
StringBuilder result = new StringBuilder();
for (String st : str) {
result.append(st + " ");
}
return result.toString().trim();
}
}Example 2:
Example 3:
Last updated