← 返回 ibm 的题目列表Find Pivot Index with Equal Left and Right Sum
类型:online_judge
ibm
Given an array of numbers, find the index of the smallest element (the pivot), for which the sums of all elements to the left and to the right are equal. The array may not be reordered.
Example
Input: arr=[1,2,3,4,6]
Output: 3
Function Description
Complete the function balancedSum.
Input parameter:
arr(n): an array of integers
Return value:
an integer representing the index of the pivot
Constraints
1 <= n <= 10^4
-1000 <= arr[i] <= 1000
Example
Input
5
1 2 3 4 6