'''
Created on 2015年11月6日
@author: SphinxW
'''
# 子數(shù)組之和
#
# 給定一個(gè)整數(shù)數(shù)組辅甥,找到和為零的子數(shù)組瞒瘸。你的代碼應(yīng)該返回滿足要求的子數(shù)組的起始位置和結(jié)束位置
# 樣例
#
# 給出[-3, 1, 2, -3, 4]备恤,返回[0, 2] 或者 [1, 3].
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
for head in range(len(nums)):
sum = nums[head]
if sum == 0:
return [head, head]
for next in range(head + 1, len(nums)):
sum += nums[next]
if sum == 0:
return [head, next]