1493.cpp (349B)
1 class Solution { 2 public: 3 int longestSubarray(const vector<int> &nums) { 4 int res = 0, left = 0, zero = -1, i; 5 for (i = 0; i < nums.size(); i++) { 6 if (nums[i]) continue; 7 res = max(res, i - left); 8 left = zero + 1; 9 zero = i; 10 } 11 return max(res, i - left) - 1; 12 } 13 };