### Problem
Return the leftmost index whose strictly-left sum equals its strictly-right sum. Exclude the indexed element itself. An empty side has sum zero. Return -1 if no position qualifies.
```cpp
class Solution {
public:
int pivotIndex(vector<int>& nums);
};
```
### Examples
**Example 1:**
```text
nums = [2,1,2]
Output: 1
Explanation: Both side sums equal 2.
```
**Example 2:**
```text
nums = [0,0]
Output: 0
Explanation: Both positions qualify, so choose the first.
```
### Constraints
- Array size is between 1 and 10000.
- Values lie in [-1000,1000].
### Contract considerations
Exclude the pivot itself and break ties toward the smallest index.
```hint Read the boundary condition
Can the right-side sum be recovered from one total?
```
### Boundary reminders
Exclude the pivot itself and break ties toward the smallest index.
Overview: Find the First Position with Balanced Side Sums. Return the leftmost index whose strictly-left sum equals its strictly-right sum.
Return the leftmost index whose strictly-left sum equals its strictly-right sum. Exclude the indexed element itself. An empty side has sum zero. Return -1 if no position qualifies.
class Solution {
public:
int pivotIndex(vector<int>& nums);
};
Examples
Example 1:
nums = [2,1,2]
Output: 1
Explanation: Both side sums equal 2.
Example 2:
nums = [0,0]
Output: 0
Explanation: Both positions qualify, so choose the first.
Constraints
Array size is between 1 and 10000.
Values lie in [-1000,1000].
Contract considerations
Exclude the pivot itself and break ties toward the smallest index.
Boundary reminders
Exclude the pivot itself and break ties toward the smallest index.