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
#前缀和写法,只要取得后面的前缀和和前面的前缀和相等的情况即可
perfixsum_hash = {0: -1}
prefix_sum = 0for i, num in enumerate(nums):
prefix_sum += num
if prefix_sum in perfixsum_hash:
#减去的是后面减去前面的前缀和,返回的应该是prefixsum_hash[prefix_sum] + 1, i
return perfixsum_hash[prefix_sum] + 1, i
perfixsum_hash[prefix_sum] = i