2129. 将标题首字母大写
class Solution:
def capitalizeTitle(self, title: str) -> str:
ret = []
for word in title.split():
if len(word) <= 2:
ret.append(word.lower())
else:
ret.append(word[0].upper() + word[1:].lower())
return ' '.join(ret)

class Solution {
public:
string capitalizeTitle(string title) {
int n = title.size();
int left = 0, right = 0;
while (right < n){
while (right < n && title[right] != ' '){
++right;
}
if (right - left > 2){
title[left++] = toupper(title[left]);
}
while (left < right){
title[left++] = tolower(title[left]);
}
left = ++right;
}
return title;
}
};