Subarray Sum
Example
Solution
class Solution:
"""
@param nums: A list of integers
@return: A list of integers includes the index of the first number
and the index of the last number
"""
def subarraySum(self, nums):
# write your code here
d = {0:-1}
n = len(nums)
sum = 0
for i in range(n):
sum += nums[i]
if sum in d:
return [d[sum] + 1, i]
d[sum] = i
return [-1, -1]Last updated