犹豫,两个学校(均非牛校)的选择# Law - 律师事务所
b*y
1 楼
☆─────────────────────────────────────☆
wmbyhh (wmbyhh) 于 (Wed Jul 16 16:32:01 2008) 提到:
Find the sequence of consecutive numbers that add up to a maximum (or
highest) total within the array. Write a function to find the sum and also
the start and end positions of the sequence. The solution should be of O(N)
time complexity.
For example if the array is (0, -1, 2, -1, 3, -1, 0), maximum sum would be 4
(= 2 + -1 + 3).
I can only figure out way of O(N^2), but how can it be done with O(N)?
☆───
wmbyhh (wmbyhh) 于 (Wed Jul 16 16:32:01 2008) 提到:
Find the sequence of consecutive numbers that add up to a maximum (or
highest) total within the array. Write a function to find the sum and also
the start and end positions of the sequence. The solution should be of O(N)
time complexity.
For example if the array is (0, -1, 2, -1, 3, -1, 0), maximum sum would be 4
(= 2 + -1 + 3).
I can only figure out way of O(N^2), but how can it be done with O(N)?
☆───