当前位置:网站首页>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
边栏推荐
- 数字电路基础(五)算术运算电路
- Global and Chinese markets of Iam security services 2022-2028: Research Report on technology, participants, trends, market size and share
- Statistics 8th Edition Jia Junping Chapter 1 after class exercises and answers summary
- Detailed introduction to dynamic programming (with examples)
- Global and Chinese market of portable and handheld TVs 2022-2028: Research Report on technology, participants, trends, market size and share
- Why can swing implement a form program by inheriting the JFrame class?
- High concurrency programming series: 6 steps of JVM performance tuning and detailed explanation of key tuning parameters
- JDBC 的四种连接方式 直接上代码
- Vysor uses WiFi wireless connection for screen projection_ Operate the mobile phone on the computer_ Wireless debugging -- uniapp native development 008
- Statistics 8th Edition Jia Junping Chapter 4 Summary and after class exercise answers
猜你喜欢
What is the transaction of MySQL? What is dirty reading and what is unreal reading? Not repeatable?
数字电路基础(一)数制与码制
Vysor uses WiFi wireless connection for screen projection_ Operate the mobile phone on the computer_ Wireless debugging -- uniapp native development 008
Query method of database multi table link
Opencv recognition of face in image
The common methods of servlet context, session and request objects and the scope of storing data in servlet.
Quaternion -- basic concepts (Reprint)
5分钟掌握机器学习鸢尾花逻辑回归分类
Build your own application based on Google's open source tensorflow object detection API video object recognition system (II)
Fundamentals of digital circuit (V) arithmetic operation circuit
随机推荐
JDBC 的四种连接方式 直接上代码
How to solve the poor sound quality of Vos?
Flash implements forced login
[pointer] solve the last person left
Differences between select, poll and epoll in i/o multiplexing
Cc36 different subsequences
[oiclass] share prizes
Install and run tensorflow object detection API video object recognition system of Google open source
王爽汇编语言详细学习笔记二:寄存器
数字电路基础(一)数制与码制
STC-B学习板蜂鸣器播放音乐2.0
ucore lab7 同步互斥 实验报告
[pointer] counts the number of times one string appears in another string
Matplotlib绘图快速入门
The four connection methods of JDBC are directly coded
1.支付系统
Detailed introduction to dynamic programming (with examples)
Keil5-MDK的格式化代码工具及添加快捷方式
Logstack introduction and deployment -- elasticstack (elk) work notes 019
ucore lab2 物理内存管理 实验报告