摘要:
Examples: { -100, 1, 2, 3, -20, -20, -20, 2, 2, 2, 2,-100 }; Answer: 8{ 1,2,3}; Answer: 6{ -1,-2,-3}; Answer: -1Solution:O(n) Solution is to use dynamic programming. You can add numbers as you walk the array in the following manner:X[i]=X[i]+X[i-1];So, at each step X[i] would contain the sum of all 阅读全文