当前位置:网站首页>Leetcode array question brushing notes
Leetcode array question brushing notes
2022-07-05 13:54:00 【Cwxh0125】
485. Maximum continuous 1 The number of
Given a binary array , Calculate the maximum continuity 1 The number of .
Ideas : Let's go through the array first , Use a variable count To record 1 The number of When I meet 1 Change quantity ++, If encountered 0 Return to zero . You also need to use a variable maxcount To record the maximum
Method 1
int findMaxConsecutiveOnes(int* nums, int numsSize){
int count=0,maxCount=0; // Define two variables
for(int i=0;i<numsSize ;i++){ // Traversal array
if(nums[i]==1) // if The value is 1 be count++
{count++;}
else {
maxCount=fmax(count,maxCount); // If zero is encountered Then make the current variable value and maxcount Compare the largest
count=0; // After zero send count Zero value
}
}
maxCount=fmax(count,maxCount);
return maxCount;
}
边栏推荐
- What is information security? What is included? What is the difference with network security?
- Controller in laravel framework
- ::ffff:192.168.31.101 是一个什么地址?
- ETCD数据库源码分析——集群间网络层客户端peerRt
- JS takes key and value from an array object to form a new object
- 什么叫做信息安全?包含哪些内容?与网络安全有什么区别?
- Xampp configuring multiple items
- Recommendation number | what are interesting people looking at?
- 国富氢能冲刺科创板:拟募资20亿 应收账款3.6亿超营收
- Summit review | baowanda - an integrated data security protection system driven by compliance and security
猜你喜欢
【云资源】云资源安全管理用什么软件好?为什么?
Idea set method annotation and class annotation
French scholars: the explicability of counter attack under optimal transmission theory
Convolutional Neural Networks简述
How to deal with the Yellow Icon during the installation of wampserver
Usage, installation and use of TortoiseSVN
Redis6 transaction and locking mechanism
UE source code reading [1]--- starting with problems delayed rendering in UE
那些考研后才知道的事
Mmseg - Mutli view time series data inspection and visualization
随机推荐
Liste des liens (simple)
Basic characteristics and isolation level of transactions
链表(简单)
These 18 websites can make your page background cool
【华南理工大学】考研初试复试资料分享
Convolutional Neural Networks简述
Multi person cooperation project to see how many lines of code each person has written
What is information security? What is included? What is the difference with network security?
2022 construction welder (special type of construction work) special operation certificate examination question bank and online simulation examination
Why do I support bat to dismantle "AI research institute"
PHP generate Poster
我为什么支持 BAT 拆掉「AI 研究院」
Wechat app payment callback processing method PHP logging method, notes. 2020/5/26
Rk3566 add LED
嵌入式软件架构设计-消息交互
Personal component - message prompt
金融壹账通香港上市:市值63亿港元 叶望春称守正笃实,久久为功
网络安全-HSRP协议
The development of speech recognition app with uni app is simple and fast.
Introduction to Chapter 8 proof problem of njupt "Xin'an numeral base"