LyWang

subarray_sum

Nov 25th, 2018
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.47 KB | None | 0 0
  1. class Solution:
  2.     """
  3.    @param nums: A list of integers
  4.    @return: A list of integers includes the index of the first number and the index of the last number
  5.    """
  6.     def subarraySum(self, nums):
  7.         # write your code here
  8.         sums = [0]
  9.         i = 0
  10.         for num in nums:
  11.             sums.append(sums[i]+num)
  12.             i+=1
  13.         for i in range(len(sums)):
  14.             if sums[i] in sums[i+1:]:
  15.                 return [i,sums.index(sums[i])-1]
Add Comment
Please, Sign In to add comment