当前位置:网站首页>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
边栏推荐
- Using flask_ Whooshalchemyplus Jieba realizes global search of flask
- 150 common interview questions for software testing in large factories. Serious thinking is very valuable for your interview
- 刷视频的功夫,不如看看这些面试题你掌握了没有,慢慢积累月入过万不是梦。
- CSAPP homework answers chapter 789
- Statistics 8th Edition Jia Junping Chapter 2 after class exercises and answer summary
- How to solve the poor sound quality of Vos?
- 【指针】统计一字符串在另一个字符串中出现的次数
- Fundamentals of digital circuits (III) encoder and decoder
- [pointer] use the insertion sorting method to arrange n numbers from small to large
- 数字电路基础(五)算术运算电路
猜你喜欢
STC-B学习板蜂鸣器播放音乐2.0
Fundamentals of digital circuit (IV) data distributor, data selector and numerical comparator
基于485总线的评分系统双机实验报告
Want to learn how to get started and learn software testing? I'll give you a good chat today
Logstack introduction and deployment -- elasticstack (elk) work notes 019
Build your own application based on Google's open source tensorflow object detection API video object recognition system (II)
Leetcode simple question: check whether two strings are almost equal
Practical cases, hand-in-hand teaching you to build e-commerce user portraits | with code
Cadence physical library lef file syntax learning [continuous update]
Query method of database multi table link
随机推荐
Logstack introduction and deployment -- elasticstack (elk) work notes 019
“Hello IC World”
Function: calculates the number of uppercase letters in a string
UCORE lab1 system software startup process experimental report
HackTheBox-Emdee five for life
【指针】数组逆序重新存放后并输出
[HCIA continuous update] advanced features of routing
Detailed introduction to dynamic programming (with examples)
[Ogg III] daily operation and maintenance: clean up archive logs, register Ogg process services, and regularly back up databases
【指针】统计一字符串在另一个字符串中出现的次数
Global and Chinese market of maleic acid modified rosin esters 2022-2028: Research Report on technology, participants, trends, market size and share
Express
Global and Chinese markets of Iam security services 2022-2028: Research Report on technology, participants, trends, market size and share
Differences between select, poll and epoll in i/o multiplexing
Rearrange spaces between words in leetcode simple questions
Maximum nesting depth of parentheses in leetcode simple questions
Oracle foundation and system table
Zhejiang University Edition "C language programming experiment and exercise guide (3rd Edition)" topic set
Global and Chinese market of goat milk powder 2022-2028: Research Report on technology, participants, trends, market size and share
Global and Chinese market of portable and handheld TVs 2022-2028: Research Report on technology, participants, trends, market size and share