We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent afd4ace commit f0af670Copy full SHA for f0af670
continuous_subarray_sum.py
@@ -0,0 +1,21 @@
1
+# -*- coding: utf-8 -*-
2
+
3
+class Solution:
4
+ # @param {int[]} A an integer array
5
+ # @return {int[]} A list of integers includes the index of the
6
+ # first number and the index of the last number
7
+ def continuousSubarraySum(self, A):
8
+ # Write your code here
9
+ _max = A[0]
10
+ _sum = 0
11
+ start, end = 0, 0
12
+ curr_start = 0 # 记录子数组开始位置
13
+ for i in xrange(len(A)):
14
+ _sum += A[i]
15
+ if _sum > _max:
16
+ _max = _sum
17
+ start, end = curr_start, i
18
+ if _sum < 0:
19
+ curr_start = i + 1
20
21
+ return [start, end]
0 commit comments