思路:
// @Title: 将标题首字母大写 (Capitalize the Title)
// @Author: qisiii
// @Date: 2024-03-11 10:53:54
// @Runtime: 3 ms
// @Memory: 41.6 MB
// @comment:
// @flag:
class Solution {
public String capitalizeTitle(String title) {
String[] strs = title.split(" ");
StringBuilder strb = new StringBuilder();
for (String s : strs) {
s = s.toLowerCase();
if (s.length() > 2) {
char c = s.charAt(0);
strb.append(String.valueOf(c).toUpperCase());
strb.append(s.substring(1));
}else{
strb.append(s);
}
strb.append(" ");
}
return strb.toString().trim();
}
}