<jupyter_start><jupyter_text>说明：    给定一个整数nums数组，编写一个返回该数组“ pivot”索引的方法。    我们将pivot index定义为索引，其中索引左侧的所有数字的总和等于索引右侧的所有数字的总和。    如果没有这样的索引，我们应该返回-1。如果有多个pivot index引，    则应返回最左侧的枢轴索引。Example 1:    Input: nums = [1,7,3,6,5,6]    Output: 3    Explanation:        The sum of the numbers to the left of index 3 (nums[3] = 6) is equal to the sum of numbers to the right of index 3.        Also, 3 is the first index where this occurs.Example 2:    Input: nums = [1,2,3]    Output: -1    Explanation:        There is no index that satisfies the conditions in the problem statement.Constraints:    1、The length of nums will be in the range [0, 10000].    2、Each element nums[i] will be an integer in the range [-1000, 1000].<jupyter_code>class Solution:
    def pivotIndex(self, nums) -> int:
        if not nums or len(nums) == 2: return -1
        left, sum_left, sum_nums = 0, 0, sum(nums)
        while left < len(nums):
            if sum_left == sum_nums - sum_left - nums[left]:
                return left
            sum_left += nums[left]
            left += 1
        return -1
nums_ = [1,7,3,6,5,6]
solution = Solution()
solution.pivotIndex(nums_)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10067681895093063, 'fraction_numerical': 0.03976311336717428, 'mean_word_length': 2.878688524590164, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '645850', 'license': 'Apache-2.0', 'n_tokens_mistral': 489, 'n_tokens_neox': 475, 'n_words': 132, 'path': 'Array/0920/724. Find Pivot Index.ipynb', 'repo_name': 'YuHe0108/Leetcode', 'size': '1182'}