Find Pivot Index

Given an array of integers, calculate the pivot index of the array, which is the index where the sum of all numbers strictly to the left is equal to the sum of all numbers strictly to the right. Return the leftmost pivot index. If no such index exists, return -1.

Constraints

  • 1 <= nums.length <= 10^4
  • -1000 <= nums[i] <= 1000
Saving… · 2 lines
class Solution:
def findPivotIndex(self, nums) -> int:
Console

Click Run to execute sample tests.