Skip to content

Commit

Permalink
Create fair-indexes.py
Browse files Browse the repository at this point in the history
  • Loading branch information
yingl authored Feb 10, 2022
1 parent 4d5037b commit 240f703
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions fair-indexes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
class Solution:
"""
@param A: an array of integers
@param B: an array of integers
@return: return a integer indicating the number of fair indexes.
"""
def CountIndexes(self, A, B):
# Write your code here.
r = 0
l = len(A)
sa, sb = sum(A), sum(B)
if sa != sb:
return 0
t = int(sa / 2)
ha, hb = 0, 0
for i in range(l - 1):
ha += A[i]
hb += B[i]
if (ha == hb) and (ha == t):
r += 1
return r

# medium: https://www.lintcode.com/problem/1882/

0 comments on commit 240f703

Please sign in to comment.