当前位置:网站首页>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

边栏推荐
- 函数:字符串反序存放
- Statistics 8th Edition Jia Junping Chapter 2 after class exercises and answer summary
- Global and Chinese markets for complex programmable logic devices 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese markets of cobalt 2022-2028: Research Report on technology, participants, trends, market size and share
- Software testing interview summary - common interview questions
- Common Oracle commands
- The minimum number of operations to convert strings in leetcode simple problem
- Function: calculates the number of uppercase letters in a string
- {1,2,3,2,5} duplicate checking problem
- Install and run tensorflow object detection API video object recognition system of Google open source
猜你喜欢

Rearrange spaces between words in leetcode simple questions

Interview Essentials: what is the mysterious framework asking?

移植蜂鸟E203内核至达芬奇pro35T【集创芯来RISC-V杯】(一)

ucore lab7 同步互斥 实验报告

"If life is just like the first sight" -- risc-v

Description of Vos storage space, bandwidth occupation and PPS requirements

Summary of thread implementation

CSAPP家庭作業答案7 8 9章

数字电路基础(四) 数据分配器、数据选择器和数值比较器

MySQL development - advanced query - take a good look at how it suits you
随机推荐
[pointer] find the largest string
Global and Chinese markets for GaN on diamond semiconductor substrates 2022-2028: Research Report on technology, participants, trends, market size and share
Statistics 8th Edition Jia Junping Chapter 4 Summary and after class exercise answers
Function: string storage in reverse order
Global and Chinese markets of PIM analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
数字电路基础(五)算术运算电路
Investment operation steps
【指针】统计一字符串在另一个字符串中出现的次数
JDBC 的四种连接方式 直接上代码
Express
Using flask_ Whooshalchemyplus Jieba realizes global search of flask
High concurrency programming series: 6 steps of JVM performance tuning and detailed explanation of key tuning parameters
Software testing interview summary - common interview questions
Logstack introduction and deployment -- elasticstack (elk) work notes 019
[oiclass] maximum formula
Description of Vos storage space, bandwidth occupation and PPS requirements
How to transform functional testing into automated testing?
China's county life record: go upstairs to the Internet, go downstairs' code the Great Wall '
Daily code 300 lines learning notes day 9
CSAPP homework answers chapter 789