-
-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy path485.java
More file actions
45 lines (44 loc) · 1.31 KB
/
485.java
File metadata and controls
45 lines (44 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
__________________________________________________________________________________________________
sample 1 ms submission
class Solution {
public int findMaxConsecutiveOnes(int[] nums) {
int max = 0;
if (nums != null && nums.length > 0) {
int pos = 0;
while(pos < nums.length) {
int count = 0;
while(nums[pos++] == 1) {
count++;
if (pos == nums.length) {
break;
}
}
if (count > 0 && max < count) {
max = count;
}
}
}
return max;
}
}
__________________________________________________________________________________________________
sample 39136 kb submission
class Solution {
public int findMaxConsecutiveOnes(int[] nums) {
int count = 0;
int act = 0;
for (int i = 0; i < nums.length; i++) {
if (nums[i] == 1) {
act++;
}
if (act > count) {
count = act;
}
if(nums[i] == 0) {
act=0;
}
}
return count;
}
}
__________________________________________________________________________________________________