当前位置:网站首页>The maximum number of words in the sentence of leetcode simple question
The maximum number of words in the sentence of leetcode simple question
2022-07-06 15:07:00 【·Starry Sea】
subject
One The sentence By some word And a single space between them , There will be no extra spaces at the beginning and end of the sentence .
Here's an array of strings sentences , among sentences[i] Represents a single The sentence .
Please return to a single sentence The maximum number of words .
Example 1:
Input :sentences = [“alice and bob love leetcode”, “i think so too”, “this is great thanks very much”]
Output :6
explain :
- The first sentence “alice and bob love leetcode” All in all 5 Word .
- The second sentence “i think so too” All in all 4 Word .
- The third sentence “this is great thanks very much” All in all 6 Word .
therefore , The third sentence has the largest number of words in a single sentence , All in all 6 Word .
Example 2:
Input :sentences = [“please wait”, “continue to fight”, “continue to win”]
Output :3
explain : There may be more than one sentence with the same number of words .
In this case , The second sentence and the third sentence ( Bold italics ) There are the same number of words .
Tips :
1 <= sentences.length <= 100
1 <= sentences[i].length <= 100
sentences[i] Only lowercase letters and ’ ’ .
sentences[i] There are no spaces at the beginning and end of .
sentences[i] All words in are separated by a single space .
source : Power button (LeetCode)
Their thinking
Because in the sentence given by the title , Every sentence is very neat , So count the number of words in each sentence , Just count the number of spaces .
class Solution:
def mostWordsFound(self, sentences: List[str]) -> int:
MAX=0
for i in sentences:
count=i.count(' ')
if MAX<count:
MAX=count
return MAX+1
边栏推荐
- Es full text index
- [oiclass] share prizes
- [pointer] delete all spaces in the string s
- Pointers: maximum, minimum, and average
- Réponses aux devoirs du csapp 7 8 9
- 刷视频的功夫,不如看看这些面试题你掌握了没有,慢慢积累月入过万不是梦。
- Four methods of exchanging the values of a and B
- 数字电路基础(四) 数据分配器、数据选择器和数值比较器
- Global and Chinese markets of PIM analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
- Get started with Matplotlib drawing
猜你喜欢
Interview Essentials: what is the mysterious framework asking?
Practical cases, hand-in-hand teaching you to build e-commerce user portraits | with code
C language do while loop classic Level 2 questions
Statistics 8th Edition Jia Junping Chapter XIII Summary of knowledge points of time series analysis and prediction and answers to exercises after class
Vysor uses WiFi wireless connection for screen projection_ Operate the mobile phone on the computer_ Wireless debugging -- uniapp native development 008
Investment operation steps
Leetcode simple question: check whether the numbers in the sentence are increasing
Fundamentals of digital circuit (IV) data distributor, data selector and numerical comparator
Maximum nesting depth of parentheses in leetcode simple questions
“Hello IC World”
随机推荐
【指针】删除字符串s中的所有空格
函数:求两个正数的最大公约数和最小公倍
Expanded polystyrene (EPS) global and Chinese markets 2022-2028: technology, participants, trends, market size and share Research Report
[HCIA continuous update] advanced features of routing
DVWA exercise 05 file upload file upload
王爽汇编语言详细学习笔记二:寄存器
Differences between select, poll and epoll in i/o multiplexing
The common methods of servlet context, session and request objects and the scope of storing data in servlet.
The number of reversing twice in leetcode simple question
Public key box
ByteDance ten years of experience, old bird, took more than half a year to sort out the software test interview questions
MySQL development - advanced query - take a good look at how it suits you
[pointer] use the insertion sorting method to arrange n numbers from small to large
Rearrange spaces between words in leetcode simple questions
UCORE lab1 system software startup process experimental report
Transplant hummingbird e203 core to Da Vinci pro35t [Jichuang xinlai risc-v Cup] (I)
STC-B学习板蜂鸣器播放音乐
Global and Chinese market for antiviral coatings 2022-2028: Research Report on technology, participants, trends, market size and share
【指针】求解最后留下的人
Interview Essentials: what is the mysterious framework asking?