Skip to content

Latest commit

 

History

History
19 lines (17 loc) · 412 Bytes

724.md

File metadata and controls

19 lines (17 loc) · 412 Bytes

724. Find Pivot Index

Solution 1 (time O(n), space O(1))

class Solution(object):
    def pivotIndex(self, nums):
        """
        :type nums: List[int]
        :rtype: int
        """
        nums_sum = sum(nums)
        cur_sum = 0
        for i, num in enumerate(nums):
            if cur_sum * 2 + num == nums_sum:
                return i
            cur_sum += num
        return -1