mirror of
https://github.com/autistic-symposium/master-algorithms-py.git
synced 2025-04-29 12:16:14 -04:00
18 lines
301 B
Python
18 lines
301 B
Python
#!/usr/bin/env python3
|
|
# -*- coding: utf-8 -*-
|
|
# author: bt3gl
|
|
|
|
|
|
def pivot_index(nums):
|
|
|
|
s, left_sum = sum(nums), 0
|
|
|
|
for i, x in enumerate(nums):
|
|
|
|
if left_sum == (s - left_sum - x):
|
|
return i
|
|
|
|
left_sum += x
|
|
|
|
return -1
|