当前位置:网站首页>Deduct one question every day - 2114. The maximum number of words in the sentence
Deduct one question every day - 2114. The maximum number of words in the sentence
2022-07-25 08:29:00 【GUI?】
# 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 .
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 .
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 .
Code demonstration
class Solution {
public int mostWordsFound(String[] sentences) {
int max = 0;
for(int i=0;i<sentences.length;i++){
int num = sentences[i].split(" ").length;
max = Math.max(num, max);
}
return max;
}
}
source : Power button (LeetCode)
link :https://leetcode.cn/problems/maximum-number-of-words-found-in-sentences
Copyright belongs to the network . For commercial reprint, please contact the official authority , Non-commercial reprint please indicate the source .
边栏推荐
- Advanced C language (11) - user defined data types
- 【5G NR】UE注册拒绝原因
- 机器学习理论及案例分析(part1)--机器学习基础
- @Principle of Autowired annotation
- CAS operation
- Apartment repair reporting system (idea, SSM, MySQL)
- Can Flink's current capabilities support the synchronization of a table from source (MySQL) to sink (MySQL) to separate databases and tables
- 【黑马程序员】Redis学习笔记002:持久化:RDB 和 AOF
- [dark horse programmer] redis learning notes 005: enterprise level solutions
- 递归调用实现打印一个整数的每一位
猜你喜欢

Data warehouse ODS, DWD floor, 220616, HM,

serialization and deserialization

Test the mock data method of knowing and knowing

DIY can decorate the mall system, you can also have!

JS cool rolling picture deformation animation JS special effects

Raspberry connects EC20 for PPP dialing

Idea reads configuration files such as validationmessages.properties Chinese garbled

Ensembles in RNA counts data in TCGA_ ID to gene_ Method of ID

Rstudio shows that it can't connect to the web page, or it has a new website.

Pricing is arbitrary, products are difficult to distinguish between true and false, and platforms are running away. Will the Tibetan market continue to be popular?
随机推荐
孙子兵法随感
Review the second time, 220614, video, day03_ Data warehouse design,
第3章业务功能开发(实现全选按钮实时的响应)
Didi eta (estimate the travel time)
A simple hotel background management system based on jsp+servlet+mysql
Raspberry pie 3b ffmpeg RTMP streaming
ArcGIS Pro脚本工具(10)——从图层生成.stylx样式符号
NVIDIA programmable reasoning accelerator tensorrt learning notes (II) - practical operation
Can Flink's current capabilities support the synchronization of a table from source (MySQL) to sink (MySQL) to separate databases and tables
哈希表刷题(上)
JS pop up picture Lightbox light box plug-in spotlight.js
Mogdb 3.0 how to add a standby database in the environment of one active and one standby
[shader realizes shadow projection effect _shader effect Chapter 8]
MVC mode three-tier architecture
@Differences between requestparam, @pathparam, @pathvariable and other annotations (use of some annotations)
【芝麻街一家】& Bert Bart RoBERTa
【5G NR】UE注册拒绝原因
Raspberry pie CM4 -- using metartc3.0 to integrate ffmpeg to realize webrtc push-pull streaming
Redis best practices
Hotel room management system based on jsp+servlet+mysql