Given a binary array, find the maximum number of consecutive 1s in this array.
Example:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutive 1s.The maximum number of consecutive 1s is 3.Note:1. The input array will only contain 0 and 1.2. The length of input array is a positive integer and will not exceed 10,000
Solution
int findMaxConsecutiveOnes(int* nums, int numsSize) { int temp_max = 0,max = 0; for (int i = 0;i < numsSize;i++) { if (nums[i] == 1) { temp_max++; } else { if (temp_max > max) max = temp_max; temp_max = 0; } } if (temp_max > max) max = temp_max; return max;}