Is Example 2 Wrong?


  • 0

    Given nums = [-2, -1, 2, 1], k = 1,
    return 2. (because the subarray [-1, 2] sums to 1 and is the longest)
    Why not [-2, 2, 1]? the sum is 1 and length is 3.


  • 1
    C

    Because the subarray has to be contiguous. Continuous adjacent neighbors without skipping any elements.


Log in to reply
 

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