From 12e1cd35441cdc6ca30a190eebd6cbe945a06f66 Mon Sep 17 00:00:00 2001 From: Steve0x2a Date: Sun, 15 Aug 2021 13:33:14 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A00724=E5=AF=BB=E6=89=BE?= =?UTF-8?q?=E6=95=B0=E7=BB=84=E7=9A=84=E4=B8=AD=E5=BF=83=E7=B4=A2=E5=BC=95?= =?UTF-8?q?=20Python=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problems/0724.寻找数组的中心索引.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/problems/0724.寻找数组的中心索引.md b/problems/0724.寻找数组的中心索引.md index 3ed68d47..052d4c02 100644 --- a/problems/0724.寻找数组的中心索引.md +++ b/problems/0724.寻找数组的中心索引.md @@ -90,6 +90,15 @@ class Solution { ## Python ```python +class Solution: + def pivotIndex(self, nums: List[int]) -> int: + numSum = sum(nums) #数组总和 + leftSum = 0 + for i in range(len(nums)): + if numSum - leftSum -nums[i] == leftSum: #左右和相等 + return i + leftSum += nums[i] + return -1 ``` ## Go