Given an integer array nums, return the pivot index: the leftmost index where the sum of all numbers strictly to its left equals the sum of all numbers strictly to its right. An empty side sums to 0. If no such index exists, return -1.
Given an integer array nums, return the pivot index: the leftmost index where the sum of all numbers strictly to its left equals the sum of all numbers strictly to its right. An empty side sums to 0. If no such index exists, return -1.
Example 1:
Input: {"nums":[1,7,3,6,5,6]}
Output: 3
Constraints:
1≤nums.length≤104
−1000≤nums[i]≤1000
Test Cases
Input (Stdin)
Expected Output (Stdout)
Execution Result
Run code to see results.
Input
arr ={"nums":[1,7,3,6,5,6]}
Look for an index where the weight on its left balances the weight on its right.