国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(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的評論 (共 條)

分享到微博請遵守國家法律
曲沃县| 大同县| 无极县| 陕西省| 纳雍县| 海淀区| 澎湖县| 年辖:市辖区| 长寿区| 农安县| 邓州市| 禹州市| 延津县| 独山县| 苍梧县| 柳江县| 同仁县| 宝山区| 元谋县| 东明县| 和硕县| 尼勒克县| 北碚区| 炉霍县| 元朗区| 旬阳县| 衢州市| 桃源县| 水富县| 张家界市| 乌鲁木齐县| 乌拉特中旗| 宾阳县| 古丈县| 神木县| 五原县| 旬邑县| 五莲县| 广灵县| 开远市| 雅江县|