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

边栏推荐
- Login the system in the background, connect the database with JDBC, and do small case exercises
- CSAPP homework answers chapter 789
- High concurrency programming series: 6 steps of JVM performance tuning and detailed explanation of key tuning parameters
- [pointer] use the insertion sorting method to arrange n numbers from small to large
- Zhejiang University Edition "C language programming experiment and exercise guide (3rd Edition)" topic set
- [issue 18] share a Netease go experience
- Statistics 8th Edition Jia Junping Chapter 2 after class exercises and answer summary
- C language do while loop classic Level 2 questions
- Build your own application based on Google's open source tensorflow object detection API video object recognition system (II)
- Global and Chinese market of pinhole glossmeter 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

Cc36 different subsequences

The number of reversing twice in leetcode simple question

Investment operation steps

The minimum number of operations to convert strings in leetcode simple problem

STC-B学习板蜂鸣器播放音乐

CSAPP家庭作業答案7 8 9章

Login the system in the background, connect the database with JDBC, and do small case exercises

Réponses aux devoirs du csapp 7 8 9

The salary of testers is polarized. How to become an automated test with a monthly salary of 20K?

后台登录系统,JDBC连接数据库,做小案例练习
随机推荐
[pointer] delete all spaces in the string s
About the garbled code problem of superstar script
ucore lab8 文件系统 实验报告
指针--剔除字符串中的所有数字
Statistics 8th Edition Jia Junping Chapter 4 Summary and after class exercise answers
Fundamentals of digital circuits (III) encoder and decoder
Global and Chinese markets for complex programmable logic devices 2022-2028: Research Report on technology, participants, trends, market size and share
移植蜂鸟E203内核至达芬奇pro35T【集创芯来RISC-V杯】(一)
STC-B学习板蜂鸣器播放音乐
ucore lab7 同步互斥 实验报告
Stc-b learning board buzzer plays music
What is an index in MySQL? What kinds of indexes are commonly used? Under what circumstances will the index fail?
【指针】求解最后留下的人
Opencv recognition of face in image
Install and run tensorflow object detection API video object recognition system of Google open source
Keil5-MDK的格式化代码工具及添加快捷方式
With 27K successful entry ByteDance, this "software testing interview notes" has benefited me for life
STC-B学习板蜂鸣器播放音乐2.0
China's county life record: go upstairs to the Internet, go downstairs' code the Great Wall '
Practical cases, hand-in-hand teaching you to build e-commerce user portraits | with code