当前位置:网站首页>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;
}
边栏推荐
- Convolutional Neural Networks简述
- Personal component - message prompt
- 内网穿透工具 netapp
- Redis6 transaction and locking mechanism
- 法国学者:最优传输理论下对抗攻击可解释性探讨
- Requests + BS4 crawl Douban top250 movie information
- Integer = = the comparison will unpack automatically. This variable cannot be assigned empty
- Aikesheng sqle audit tool successfully completed the evaluation of "SQL quality management platform grading ability" of the Academy of communications and communications
- Set up a website with a sense of ceremony, and post it to the public 2/2 through the intranet
- Embedded software architecture design - message interaction
猜你喜欢
uplad_ Labs first three levels
Liar report query collection network PHP source code
laravel-dompdf导出pdf,中文乱码问题解决
常见问题之PHP——Fatal error: Allowed memory size of 314572800 bytes exhausted...
LeetCode_2(两数相加)
基于微信小程序的订餐系统
redis6主从复制及集群
瑞能实业IPO被终止:年营收4.47亿 曾拟募资3.76亿
搭建一个仪式感点满的网站,并内网穿透发布到公网 2/2
What are the private addresses
随机推荐
The real king of caching, Google guava is just a brother
Zibll theme external chain redirection go page beautification tutorial
Idea remote debugging agent
French scholars: the explicability of counter attack under optimal transmission theory
web3.eth. Filter related
Requests + BS4 crawl Douban top250 movie information
How to divide a large 'tar' archive file into multiple files of a specific size
荐号 | 有趣的人都在看什么?
Intranet penetration tool NetApp
Request + BS4 crawl Netease cloud music popular comments
Usage, installation and use of TortoiseSVN
Selenium crawls Baidu pictures
2022司钻(钻井)考试题库及模拟考试
Why do I support bat to dismantle "AI research institute"
[cloud resources] what software is good for cloud resource security management? Why?
Controller in laravel framework
Simple PHP paging implementation
这18个网站能让你的页面背景炫酷起来
ELK 企业级日志分析系统
LeetCode_3(无重复字符的最长子串)