2024-03-11发表2025-01-15更新LeetCode每日一题几秒读完 (大约111个字)0次访问2129. 将标题首字母大写将标题首字母大写 难度: easy 原始链接: https://leetcode.cn/problems/capitalize-the-title 标签: 模拟 解法一: 模拟go1234567891011func capitalizeTitle(title string) string { fields := strings.Fields(title) for i, field := range fields { if len(field) <= 2 { fields[i] = strings.ToLower(field) } else { fields[i] = strings.ToUpper(field[:1]) + strings.ToLower(field[1:]) } } return strings.Join(fields, " ")} java123456789101112class Solution { public String capitalizeTitle(String title) { return Arrays.stream(title.split(" ")) .map(str -> { if (str.length() <= 2) { return str.toLowerCase(); } return Character.toUpperCase(str.charAt(0)) + str.substring(1).toLowerCase(); }) .collect(Collectors.joining(" ")); }}2129. 将标题首字母大写https://wuhunyu.top/leetcode/2024/03/capitalize-the-title/index.html作者wuhunyu发布于2024-03-11更新于2025-01-15许可协议#模拟