본문 바로가기
python-algorithm

leetcode 2129. Capitalize the Title

by 무적김두칠 2022. 3. 25.

1
2
3
4
5
6
7
8
9
10
11
12
13
class Solution:
    def capitalizeTitle(self, title: str-> str:
        titleList=list(title.split())
        ans=''
        for i in titleList :
            i = i.lower()
            if len(i)<3: ans+=i
            else:                
                for j in range(len(i)):
                    if j==0 : ans+=i[j].upper()
                    else: ans+=i[j]
            ans+=' '
        return ans[:-1]
cs
반응형

댓글