Skip to content

Commit

Permalink
使用enumerate遍历,似乎更快
Browse files Browse the repository at this point in the history
  • Loading branch information
rinwf committed Sep 18, 2018
1 parent e3c0ebd commit 21d4302
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lc724. Find Pivot Index.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ def pivotIndex(self, nums):
"""
lsum = 0
rsum = sum(nums)
for i in range(len(nums)):
lsum += nums[i]

for i, num in enumerate(nums):
lsum += num
if lsum == rsum:
return i
rsum -= nums[i]
rsum -= num
else:
return -1

Expand Down

0 comments on commit 21d4302

Please sign in to comment.