724-Find-Pivot-Index

Sat 17 May 2025

https://leetcode.com/problems/find-pivot-index

import pyutil as pyu
pyu.get_local_pyinfo()
print(pyu.ps2("python-dotenv"))
from typing import List
class Solution:
  def pivotIndex(self, nums: List[int]) -> int:
    summ = sum(nums)
    prefix = 0

    for i, num in enumerate(nums):
      if prefix == summ - prefix - num:
        return i
      prefix += num

    return -1
new Solution().pivotIndex()

Score: 5

Category: leetcode