Subarray Sum
Easy Given an integer array, find a subarray where the sum of numbers is zero. Your code should return the index of the first number and the index of the last number.
Thoughts
傻办法需要三循环,。我们可以先存一个preSum数组,用来存储到从0到i-1时数组和是多少。那么为子数组为0相当于说preSum中两个成员的值相等,这两个值之所夹的子数组即所求。
Code
Anlysis
TC: O(n)
SC: O(n)
Last updated
Was this helpful?