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

边栏推荐
- How to transform functional testing into automated testing?
- STC-B学习板蜂鸣器播放音乐
- Wang Shuang's detailed notes on assembly language learning I: basic knowledge
- ByteDance ten years of experience, old bird, took more than half a year to sort out the software test interview questions
- 指针--剔除字符串中的所有数字
- About the garbled code problem of superstar script
- Statistics 8th Edition Jia Junping Chapter XIII Summary of knowledge points of time series analysis and prediction and answers to exercises after class
- The minimum sum of the last four digits of the split digit of leetcode simple problem
- 数字电路基础(五)算术运算电路
- [pointer] delete all spaces in the string s
猜你喜欢

Es full text index

Statistics 8th Edition Jia Junping Chapter 2 after class exercises and answer summary

Build your own application based on Google's open source tensorflow object detection API video object recognition system (I)

Fundamentals of digital circuit (V) arithmetic operation circuit

基于485总线的评分系统双机实验报告

CSAPP homework answers chapter 789

Fundamentals of digital circuits (I) number system and code system

Cc36 different subsequences

Stc-b learning board buzzer plays music 2.0

Keil5 MDK's formatting code tool and adding shortcuts
随机推荐
Stc-b learning board buzzer plays music
Global and Chinese markets of Iam security services 2022-2028: Research Report on technology, participants, trends, market size and share
Function: calculates the number of uppercase letters in a string
Quaternion -- basic concepts (Reprint)
DVWA exercise 05 file upload file upload
Face and eye recognition based on OpenCV's own model
Vysor uses WiFi wireless connection for screen projection_ Operate the mobile phone on the computer_ Wireless debugging -- uniapp native development 008
Global and Chinese markets for complex programmable logic devices 2022-2028: Research Report on technology, participants, trends, market size and share
What is an index in MySQL? What kinds of indexes are commonly used? Under what circumstances will the index fail?
Global and Chinese market of barrier thin film flexible electronics 2022-2028: Research Report on technology, participants, trends, market size and share
Thinking about three cups of tea
“Hello IC World”
CSAPP家庭作業答案7 8 9章
ucore lab1 系统软件启动过程 实验报告
High concurrency programming series: 6 steps of JVM performance tuning and detailed explanation of key tuning parameters
Common Oracle commands
【指针】八进制转换为十进制
ucore lab2 物理内存管理 实验报告
Report on the double computer experiment of scoring system based on 485 bus
C language learning summary (I) (under update)