Skip to content

Commit 2289128

Browse files
authored
Create capitalize-the-title.cpp
1 parent 289133d commit 2289128

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

C++/capitalize-the-title.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Time: O(n)
2+
// Space: O(1)
3+
4+
class Solution {
5+
public:
6+
string capitalizeTitle(string title) {
7+
for (int i = 0, j = 0; i <= size(title); ++i) {
8+
if (i < size(title) && title[i] != ' ') {
9+
title[i] = tolower(title[i]);
10+
continue;
11+
}
12+
if (i - j > 2) {
13+
title[j] = toupper(title[j]);
14+
}
15+
j = i + 1;
16+
}
17+
return title;
18+
}
19+
};

0 commit comments

Comments
 (0)