int findMaxConsecutiveOnes(vector<int>& nums) { int count = 0; int m=0; int n=nums.size(); for(int j=0;j<n;++j) { if(nums[j]==1) { count++; m=max(count,m); } else{ count=0; } } return m; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter