public int largestAltitude(int[] gain) {
int ans = 0;
int h = 0;
for(int x: gain) {
h += x;
ans = Math.max(ans, h);
}
return ans;
}
public int pivotIndex(int[] nums) {
int n = nums.length;
int[] left = new int[n + 1];
int[] right = new int[n + 1];
for(int i = 1; i <= n; i++)
left[i] = left[i - 1] + nums[i - 1];
for(int i = n; i > 0; i--)
right[i - 1] = right[i] + nums[i - 1];
for(int i = 0; i < n; i++) {
if(left[i] == right[i + 1]) return i;
}
return -1;
}