2129. Capitalize the Title Easy

@problem@discussion
#String



1/**
2 * [2129] Capitalize the Title
3 *
4 * You are given a string title consisting of one or more words separated by a single space, where each word consists of English letters. Capitalize the string by changing the capitalization of each word such that:
5 * 
6 * 	If the length of the word is 1 or 2 letters, change all letters to lowercase.
7 * 	Otherwise, change the first letter to uppercase and the remaining letters to lowercase.
8 * 
9 * Return the capitalized title.
10 *  
11 * Example 1:
12 * 
13 * Input: title = "capiTalIze tHe titLe"
14 * Output: "Capitalize The Title"
15 * Explanation:
16 * Since all the words have a length of at least 3, the first letter of each word is uppercase, and the remaining letters are lowercase.
17 * 
18 * Example 2:
19 * 
20 * Input: title = "First leTTeR of EACH Word"
21 * Output: "First Letter of Each Word"
22 * Explanation:
23 * The word "of" has length 2, so it is all lowercase.
24 * The remaining words have a length of at least 3, so the first letter of each remaining word is uppercase, and the remaining letters are lowercase.
25 * 
26 * Example 3:
27 * 
28 * Input: title = "i lOve leetcode"
29 * Output: "i Love Leetcode"
30 * Explanation:
31 * The word "i" has length 1, so it is lowercase.
32 * The remaining words have a length of at least 3, so the first letter of each remaining word is uppercase, and the remaining letters are lowercase.
33 * 
34 *  
35 * Constraints:
36 * 
37 * 	1 <= title.length <= 100
38 * 	title consists of words separated by a single space without any leading or trailing spaces.
39 * 	Each word consists of uppercase and lowercase English letters and is non-empty.
40 * 
41 */
42pub struct Solution {}
43
44// problem: https://leetcode.com/problems/capitalize-the-title/
45// discuss: https://leetcode.com/problems/capitalize-the-title/discuss/?currentPage=1&orderBy=most_votes&query=
46
47// submission codes start here
48
49impl Solution {
50    pub fn capitalize_title(title: String) -> String {
51        String::new()
52    }
53}
54
55// submission codes end
56
57#[cfg(test)]
58mod tests {
59    use super::*;
60
61    #[test]
62    fn test_2129() {
63    }
64}
65


Back
© 2025 bowen.ge All Rights Reserved.