【求助】
搞不懂样例为" "时我在牛客网上的结果是"",而在本地上测的结果是" "!!!
public class Solution { public static String ReverseSentence(String str) { if (str == null || str.length() <= 1) { // 处理" "的情况 return str; } StringBuilder sb = new StringBuilder(); String[] strs = str.split(" "); for (int i = strs.length - 1; i >= 0; i--) { sb.append(i == 0 ? strs[i] : strs[i] + " "); } return sb.toString(); } }