Most efficient way to sum up an array of integers
问题 I am trying to find a sub- O(n) method to calculate the sum of an integer array ~~~(instead of iterating through 0 - n , I am doing it in n/2 )~~~ I'm still doing it in O(n) . public static int sum(int[] s) { int length = s.length - 1; int half = length/2; int sum = 0; for(int i = 0; i <= half; i++) { System.out.println(i + " " + s[i] + " + " + s[length - i]); sum += s[i] + s[length - i]; } return sum; } My algorithm works for even number of integers, however, when there are odd number of