Practice/Google/Leetcode 724. Find Pivot Index
CodingMust
Given an array of integers, find the leftmost index where the sum of all elements strictly to the left of that index equals the sum of all elements strictly to the right of that index.
If no such index exists, return -1.
Elements "strictly to the left" means all elements with indices less than the current index. Elements "strictly to the right" means all elements with indices greater than the current index. The element at the index itself is not included in either sum.
-1 if no balance point existsExample 1:
` Input: nums = [1, 7, 3, 6, 5, 6] Output: 3 Explanation:
Example 2:
` Input: nums = [5] Output: 0 Explanation:
Example 3:
Input: nums = [1, 2, 3, 4] Output: -1 Explanation: No index satisfies the balance condition
Example 4:
` Input: nums = [2, 1, -1] Output: 0 Explanation: