I learned this from the decent tutorial by @zjh08177,thank you !! https://discuss.leetcode.com/topic/30941/here-is-a-10-line-template-that-can-solve-most-substring-problems

```
public class Solution {
public int findMaxConsecutiveOnes(int[] nums) {
int j=0;
int len=0;
int zero=0;
for(int i=0;i<nums.length;i++){
if(nums[i]==0){
zero++;
}
while(zero>1){
if(nums[j]==0){
zero--;
}
j++;
}
len=Math.max(i-j+1,len);
}
return len;
}
}
```