My Java solution


  • 0
    int result = 0, count = 0;
    for (int i = 0; i < nums.length - result; ++i) {
        if (nums[i] == 0) {
            continue;
        } else {
            do {
                ++count;
                ++i;
            } while (i < nums.length && nums[i] == 1);
                if (result < count) {
                    result = count;
                }
                count = 0;
            }
        }
    return result;
    

Log in to reply
 

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.