mirror of
https://github.com/youngyangyang04/leetcode-master.git
synced 2025-07-09 03:34:02 +08:00
添加0724寻找数组的中心索引 Python版本
This commit is contained in:
@ -90,6 +90,15 @@ class Solution {
|
|||||||
## Python
|
## Python
|
||||||
|
|
||||||
```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
|
## Go
|
||||||
|
Reference in New Issue
Block a user