本文準備講解1個算法編程問題, 這個算法編程問題來自LintCode平臺。不了解.LintCode平臺的讀者可以閱讀筆者文章(在線編程平臺推薦-LeetCode)。問題的英文版本描述如下:
Continuous Subarray Sum
Given an integer array, find a continuous subarray where the sum of numbers is the biggest. Your code should return the index of the first number and the index of the last number. (If their are duplicate answer, return anyone)
Example
Give[-3, 1, 3, -3, 4], return [1,4].
連續(xù)數組元素求和
給定一個整數數組效览,請找出一個連續(xù)數組元素序列,使得該數組元素序列的和最大荡短。輸出答案時,請分別返回第一個數字和最后一個數字的下標哆键。(如果存在多個答案掘托,請返回其中任意一個答案)
這道題目是1個很好的題目,但是沒有多種效能接近的算法處理方案〖冢現在公布1種高效簡單的算法方案闪盔。
高效簡單的算法方案