File tree Expand file tree Collapse file tree 2 files changed +27
-24
lines changed Expand file tree Collapse file tree 2 files changed +27
-24
lines changed Original file line number Diff line number Diff line change
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
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments