当前位置:网站首页>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
边栏推荐
- Public key box
- HackTheBox-Emdee five for life
- Global and Chinese market of portable and handheld TVs 2022-2028: Research Report on technology, participants, trends, market size and share
- The minimum number of operations to convert strings in leetcode simple problem
- Global and Chinese markets for complex programmable logic devices 2022-2028: Research Report on technology, participants, trends, market size and share
- Emqtt distribution cluster and node bridge construction
- Function: find the root of the equation by Newton iterative method
- 150 common interview questions for software testing in large factories. Serious thinking is very valuable for your interview
- Pointer -- output all characters in the string in reverse order
- [issue 18] share a Netease go experience
猜你喜欢
The minimum number of operations to convert strings in leetcode simple problem
C language do while loop classic Level 2 questions
MySQL development - advanced query - take a good look at how it suits you
What is an index in MySQL? What kinds of indexes are commonly used? Under what circumstances will the index fail?
DVWA exercise 05 file upload file upload
数字电路基础(四) 数据分配器、数据选择器和数值比较器
China's county life record: go upstairs to the Internet, go downstairs' code the Great Wall '
Query method of database multi table link
Leetcode simple question: check whether two strings are almost equal
STC-B学习板蜂鸣器播放音乐2.0
随机推荐
指针:最大值、最小值和平均值
Sleep quality today 81 points
Réponses aux devoirs du csapp 7 8 9
The minimum sum of the last four digits of the split digit of leetcode simple problem
How to use Moment. JS to check whether the current time is between 2 times
[pointer] solve the last person left
函数:求两个正数的最大公约数和最小公倍
“人生若只如初见”——RISC-V
The minimum number of operations to convert strings in leetcode simple problem
My first blog
How to solve the poor sound quality of Vos?
JDBC 的四种连接方式 直接上代码
What is an index in MySQL? What kinds of indexes are commonly used? Under what circumstances will the index fail?
150 common interview questions for software testing in large factories. Serious thinking is very valuable for your interview
What is the transaction of MySQL? What is dirty reading and what is unreal reading? Not repeatable?
Numpy Quick Start Guide
CSAPP家庭作業答案7 8 9章
With 27K successful entry ByteDance, this "software testing interview notes" has benefited me for life
指針:最大值、最小值和平均值
[issue 18] share a Netease go experience