五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

LeetCode 2129. Capitalize the Title

2023-04-24 15:18 作者:您是打尖兒還是住店呢  | 我要投稿


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:

  • If the length of the word is?1?or?2?letters, change all letters to lowercase.

  • Otherwise, change the first letter to uppercase and the remaining letters to lowercase.

Return?the?capitalized?title.

?

Example 1:

Input: title = "capiTalIze tHe titLe"

Output: "Capitalize The Title"Explanation:

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.

Example 2:

Input:?

title = "First leTTeR of EACH Word"

Output:?

"First Letter of Each Word"

Explanation:

The word "of" has length 2, so it is all lowercase.?

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.

Example 3:

Input:?

title = "i lOve leetcode"

Output: "i Love Leetcode"

Explanation:

The word "i" has length 1, so it is lowercase.?

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.

?

Constraints:

  • 1 <= title.length <= 100

  • title?consists of words separated by a single space without any leading or trailing spaces.

  • Each word consists of uppercase and lowercase English letters and is?non-empty.

以前不知道string的trim()方法,現(xiàn)在知道了,

別人2行代碼,我用將近20行,不過讀起來方便些了,代碼如下:


Runtime:?3 ms, faster than?83.17%?of?Java?online submissions for?Capitalize the Title.

Memory Usage:?42.7 MB, less than?49.66%?of?Java?online submissions for?Capitalize the Title.


LeetCode 2129. Capitalize the Title的評論 (共 條)

分享到微博請遵守國家法律
宣城市| 和硕县| 商洛市| 花莲市| 灵武市| 社旗县| 辛集市| 拜泉县| 扬中市| 惠东县| 颍上县| 根河市| 外汇| 泸州市| 上栗县| 永平县| 波密县| 盐源县| 福鼎市| 昌黎县| 资源县| 丰县| 壤塘县| 菏泽市| 绥中县| 余庆县| 沂水县| 民丰县| 北安市| 万盛区| 东明县| 丹巴县| 阳谷县| 合江县| 达孜县| 新晃| 新河县| 奉节县| 洪江市| 乐业县| 剑川县|