Faaez Razeen

Find Pivot Index

  • 1 min read
  • Array
  • LC-Easy

3 years ago

Solution

TimeSpaceExplanation
O(n)O(1)
def pivotIndex(self, nums: List[int]) -> int: lsum = 0 total_sum = sum(nums) for pivot in range(len(nums)): rsum = total_sum - lsum - nums[pivot] if lsum == rsum: return pivot lsum += nums[pivot] return -1