Skip to content

Commit 9d7780d

Browse files
committed
Add Capitialize-the-Title
1 parent cbe10a8 commit 9d7780d

File tree

2 files changed

+27
-24
lines changed

2 files changed

+27
-24
lines changed

LeetCode/Capitialize-the-Title.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# 2129. Capitalize the Title
2+
# https://leetcode.com/problems/capitalize-the-title/
3+
4+
class Solution(object):
5+
# long way:
6+
def capitalizeTitle(self, title):
7+
ans = []
8+
for item in title.split(" "):
9+
if len(item) <= 2:
10+
ans.append(item.lower())
11+
else:
12+
ans.append(item.lower().capitalize())
13+
return " ".join(ans)
14+
15+
# short way:
16+
def capitalizeTitle(self, title):
17+
return " ".join(item.lower() if len(item)<=2 else item.lower().capitalize() for item in title.split(" "))
18+
19+
20+
# Testcases
21+
# "capiTalIze tHe titLe"
22+
# "First leTTeR of EACH Word"
23+
# "i lOve leetcode"
24+
25+
# Status - Success
26+
# Runtime: 18 ms (Faster than 93.89% of Python submissions)
27+
# Memory Usage: 13.4 MB

LeetCode/Problem2129-u.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)