Find Pivot Index
Given an integer array nums, return the leftmost pivot index where the sum of all elements strictly to its left equals the sum of all elements strictly to its right. If no such index exists, return -1. The pivot's own value is excluded from both sides.
Open official problem prompt ↗Find the first split point where the array balances, left weight equal to right weight.
Balancing a seesaw: you slide the fulcrum along a plank of weights until the load on the left matches the load on the right, ignoring the plank cell directly under the fulcrum.
- Input
- nums = [1, 7, 3, 6, 5, 6]
- Output
- 3
- Why
- Left of index 3 is 1+7+3=11 and right is 5+6=11, and it is the smallest such index
1 <= nums.length <= 10^4-1000 <= nums[i] <= 1000