Class Solution

java.lang.Object
g2101_2200.s2129_capitalize_the_title.Solution

public class Solution extends Object
2129 - Capitalize the Title.<p>Easy</p> <p>You are given a string <code>title</code> consisting of one or more words separated by a single space, where each word consists of English letters. <strong>Capitalize</strong> the string by changing the capitalization of each word such that:</p> <ul> <li>If the length of the word is <code>1</code> or <code>2</code> letters, change all letters to lowercase.</li> <li>Otherwise, change the first letter to uppercase and the remaining letters to lowercase.</li> </ul> <p>Return <em>the <strong>capitalized</strong></em> <code>title</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> title = &ldquo;capiTalIze tHe titLe&rdquo;</p> <p><strong>Output:</strong> &ldquo;Capitalize The Title&rdquo;</p> <p><strong>Explanation:</strong> 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.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> title = &ldquo;First leTTeR of EACH Word&rdquo;</p> <p><strong>Output:</strong> &ldquo;First Letter of Each Word&rdquo;</p> <p><strong>Explanation:</strong></p> <p>The word &ldquo;of&rdquo; has length 2, so it is all lowercase.</p> <p>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.</p> <p><strong>Example 3:</strong></p> <p><strong>Input:</strong> title = &ldquo;i lOve leetcode&rdquo;</p> <p><strong>Output:</strong> &ldquo;i Love Leetcode&rdquo;</p> <p><strong>Explanation:</strong></p> <p>The word &ldquo;i&rdquo; has length 1, so it is lowercase.</p> <p>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.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= title.length <= 100</code></li> <li><code>title</code> consists of words separated by a single space without any leading or trailing spaces.</li> <li>Each word consists of uppercase and lowercase English letters and is <strong>non-empty</strong>.</li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • capitalizeTitle

      public String capitalizeTitle(String title)