Find Pivot Index
Easy
LC #724
prefix sumarrayNot attempted yet
Given an integer array nums, return the pivot
index: the leftmost index i where the sum of the
numbers strictly to its left equals the sum of the numbers
strictly to its right. nums[i] itself is in neither
side. An empty side sums to 0.
Return -1 if no such index exists.
Example 1
Input: nums = [1, 7, 3, 6, 5, 6]
Output: 3
Left of index 3: 1 + 7 + 3 = 11. Right: 5 + 6 = 11.
Example 2
Input: nums = [1, 2, 3]
Output: -1
Example 3
Input: nums = [2, 1, -1]
Output: 0
Left of index 0 is empty (0); right is 1 + (-1) = 0.
Constraints
- 1 ≤ len(nums) ≤ 2 · 10⁵
- -1000 ≤ nums[i] ≤ 1000