forked from fishercoder1534/Leetcode
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_2129.java
24 lines (22 loc) · 768 Bytes
/
_2129.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package com.fishercoder.solutions;
import java.util.Locale;
public class _2129 {
public static class Solution1 {
public String capitalizeTitle(String title) {
String[] words = title.split("\\ ");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < words.length; i++) {
String tmp = words[i].toLowerCase(Locale.ROOT);
if (words[i].length() <= 2) {
sb.append(tmp);
} else {
sb.append(Character.toUpperCase(tmp.charAt(0)) + tmp.substring(1));
}
if (i < words.length - 1) {
sb.append(" ");
}
}
return sb.toString();
}
}
}