当前位置:网站首页>Capitalize the title of leetcode simple question
Capitalize the title of leetcode simple question
2022-07-06 15:04:00 【·Starry Sea】
subject
Give you a string title , It consists of a single space connecting one or more words , Each word contains only English letters . Please put the first letter of each word according to the following rules Capitalization :
If the length of the word is 1 perhaps 2 , All letters in lowercase .
otherwise , Capitalize the first letter of the word , The remaining letters become lowercase .
Please return After capitalization Of title .
Example 1:
Input :title = “capiTalIze tHe titLe”
Output :“Capitalize The Title”
explain :
Because all words are at least 3 , Capitalize each word , The remaining letters become lowercase .
Example 2:
Input :title = “First leTTeR of EACH Word”
Output :“First Letter of Each Word”
explain :
word “of” The length is 2 , So it stays completely lowercase .
Other words are at least... Long 3 , So other words are capitalized , The remaining letters are lowercase .
Example 3:
Input :title = “i lOve leetcode”
Output :“i Love Leetcode”
explain :
word “i” The length is 1 , So it keeps lowercase .
Other words are at least... Long 3 , So other words are capitalized , The remaining letters are lowercase .
Tips :
1 <= title.length <= 100
title Words separated by a single space , And does not contain any leading or suffix spaces .
Each word consists of uppercase and lowercase letters , And are Non empty Of .
source : Power button (LeetCode)
Their thinking
about title Every word in , Replace case by condition .
class Solution:
def capitalizeTitle(self, title: str) -> str:
def change(matched):
word=matched.group('word')
return word.lower() if len(word)<3 else word[0].upper()+word[1:].lower()
return re.sub('(?P<word>\S+)',change,title) # Replace letters according to rules

边栏推荐
- Get started with Matplotlib drawing
- 浙大版《C语言程序设计实验与习题指导(第3版)》题目集
- [issue 18] share a Netease go experience
- Software testing interview summary - common interview questions
- [oiclass] share prizes
- HackTheBox-Emdee five for life
- 函数:求方程的根
- Statistics 8th Edition Jia Junping Chapter 10 summary of knowledge points of analysis of variance and answers to exercises after class
- DVWA exercise 05 file upload file upload
- 数字电路基础(二)逻辑代数
猜你喜欢

150 common interview questions for software testing in large factories. Serious thinking is very valuable for your interview

Statistics 8th Edition Jia Junping Chapter 10 summary of knowledge points of analysis of variance and answers to exercises after class

CSAPP家庭作业答案7 8 9章

Don't you even look at such a detailed and comprehensive written software test question?

Description of Vos storage space, bandwidth occupation and PPS requirements

“Hello IC World”

Cc36 different subsequences

Matplotlib绘图快速入门

servlet中 servlet context与 session与 request三个对象的常用方法和存放数据的作用域。

About the garbled code problem of superstar script
随机推荐
CSAPP homework answers chapter 789
Function: find 1-1/2+1/3-1/4+1/5-1/6+1/7-... +1/n
How to use Moment. JS to check whether the current time is between 2 times
Stc-b learning board buzzer plays music
flask实现强制登陆
Global and Chinese market of goat milk powder 2022-2028: Research Report on technology, participants, trends, market size and share
Face and eye recognition based on OpenCV's own model
Pointers: maximum, minimum, and average
Global and Chinese market of maleic acid modified rosin esters 2022-2028: Research Report on technology, participants, trends, market size and share
To brush the video, it's better to see if you have mastered these interview questions. Slowly accumulating a monthly income of more than 10000 is not a dream.
Using flask_ Whooshalchemyplus Jieba realizes global search of flask
Build your own application based on Google's open source tensorflow object detection API video object recognition system (I)
STC-B学习板蜂鸣器播放音乐2.0
Fundamentals of digital circuit (V) arithmetic operation circuit
线程的实现方式总结
基于485总线的评分系统双机实验报告
What is an index in MySQL? What kinds of indexes are commonly used? Under what circumstances will the index fail?
ByteDance ten years of experience, old bird, took more than half a year to sort out the software test interview questions
What is the transaction of MySQL? What is dirty reading and what is unreal reading? Not repeatable?
Réponses aux devoirs du csapp 7 8 9