Last active
September 21, 2017 09:25
-
-
Save freelze/645f7ad56fae8d00793bbc0f7875dda6 to your computer and use it in GitHub Desktop.
Runtime: 46 ms , Your runtime beats 15.21 % of cpp submissions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
using namespace std; | |
class Solution | |
{ | |
public: | |
int findMaxConsecutiveOnes(vector<int>& nums) | |
{ | |
int count = 0, max = 0; | |
for(int i=0; i<nums.size(); i++) | |
{ | |
if(nums[i] == 1) | |
{ | |
count++; | |
if(count > max) max = count; | |
} | |
else | |
{ | |
if(count > max) max = count; | |
count = 0; | |
} | |
} | |
return max; | |
} | |
}; | |
int main() | |
{ | |
vector<int> v1; | |
int arr[] = {1,0,1,1,0,1}; | |
v1.assign(arr,arr+6); | |
Solution s1; | |
cout << s1.findMaxConsecutiveOnes(v1); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment