Fair Candy Swap

import math
class Solution(object):
def fairCandySwap(self, A, B):
“”"
:type A: List[int]
:type B: List[int]
:rtype: List[int]
“”"
if not A or not B:
return []
A_sum = sum(A)
B_sum = sum(B)
result = A_sum - B_sum
dict_A = []
for index in range(len(A)):
dict_A.append(A[index])
for index in range(len(B)-1,-1,-1):
if B[index] + result / 2 in dict_A:
return [int(B[index] + result / 2), B[index]]

猜你喜欢

转载自blog.csdn.net/m0_37770463/article/details/88838749
今日推荐