[leetcode 2022-1-8 双周赛] 一、将标题首字母大写

在这里插入图片描述

相对简单

class Solution:
    def capitalizeTitle(self, title: str) -> str:
        title_all = title.split()
        title_new = []
        for t_s in title_all:
            if len(t_s) <= 2:
                title_new.append(t_s.lower())
            else:
                title_new.append(t_s.capitalize())
        return ' '.join(title_new)

猜你喜欢

转载自blog.csdn.net/weixin_45492560/article/details/122414462