Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bbdbf55

Browse files
add 2129
1 parent f3bc0e2 commit bbdbf55

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ _If you like this project, please leave me a star._ ★
88

99
| # | Title | Solutions | Video | Difficulty | Tag
1010
|-----|----------------|---------------|--------|-------------|-------------
11+
|2129|[Capitalize the Title](https://leetcode.com/problems/capitalize-the-title/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2129.java) ||Easy||
1112
|2126|[Destroying Asteroids](https://leetcode.com/problems/destroying-asteroids/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2126.java) ||Medium||
1213
|2125|[Number of Laser Beams in a Bank](https://leetcode.com/problems/number-of-laser-beams-in-a-bank/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2125.java) ||Medium||
1314
|2124|[Check if All A's Appears Before All B's](https://leetcode.com/problems/check-if-all-as-appears-before-all-bs/)|[Java](../master/src/main/java/com/fishercoder/solutions/_2124.java) ||Easy||
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.fishercoder.solutions;
2+
3+
import java.util.Locale;
4+
5+
public class _2129 {
6+
public static class Solution1 {
7+
public String capitalizeTitle(String title) {
8+
String[] words = title.split("\\ ");
9+
StringBuilder sb = new StringBuilder();
10+
for (int i = 0; i < words.length; i++) {
11+
String tmp = words[i].toLowerCase(Locale.ROOT);
12+
if (words[i].length() <= 2) {
13+
sb.append(tmp);
14+
} else {
15+
sb.append(Character.toUpperCase(tmp.charAt(0)) + tmp.substring(1));
16+
}
17+
if (i < words.length - 1) {
18+
sb.append(" ");
19+
}
20+
}
21+
return sb.toString();
22+
}
23+
}
24+
}

0 commit comments

Comments
 (0)