Alice and Bob have candy bars of different sizes: A[i] is the size of the i-th bar of candy that Alice has, and B[j] is the size of the j-th bar of candy that Bob has.

Since they are friends, they would like to exchange one candy bar each so that after the exchange, they both have the same total amount of candy.  (The total amount of candy a person has is the sum of the sizes of candy bars they have.)

Return an integer array ans where ans[0] is the size of the candy bar that Alice must exchange, and ans[1] is the size of the candy bar that Bob must exchange.

If there are multiple answers, you may return any one of them.  It is guaranteed an answer exists.

Example 1:

Input: A = [1,1], B = [2,2]
Output: [1,2]

Example 2:

Input: A = [1,2], B = [2,3]
Output: [1,2]

Example 3:

Input: A = [2], B = [1,3]
Output: [2,3]

Example 4:

Input: A = [1,2,5], B = [2,4]
Output: [5,4]

Note:

  • 1 <= A.length <= 10000
  • 1 <= B.length <= 10000
  • 1 <= A[i] <= 100000
  • 1 <= B[i] <= 100000
  • It is guaranteed that Alice and Bob have different total amounts of candy.
  • It is guaranteed there exists an answer.
class Solution(object):
def fairCandySwap(self, A, B):
"""
:type A: List[int]
:type B: List[int]
:rtype: List[int]
"""
diff=(sum(A)-sum(B))/2
A=set(A)
for b in set(B):
if b+diff in A:
return b+diff, b

  

最新文章

  1. Spark概述
  2. SQLSERVER中的假脱机spool
  3. C++线程中packaged_tack
  4. JavaScript中对象的比较
  5. HTML5适合移动应用开发的几大特性
  6. 【转】maven导出项目依赖的jar包
  7. Java静态代码分析工具——FindBugs插件的安装与使用
  8. HttpContext.Current.Cache在控制台下不工作
  9. winform 发邮件
  10. 虚幻4以及DX12将允许开发者利用Xbox One的更多性能(转)
  11. cocos2dx中的背景图层CCLayerColor和渐变图层CCLayerGradient
  12. error: dst ref refs/heads/zhCN_v0.13.1 receives from more than one src.
  13. Hibernate从入门到精通(六)一对一双向关联映射
  14. webApp添加到iOS桌面
  15. 细聊 Cocoapods 与 Xcode 工程配置
  16. 语音频谱语音信号处理之(四)梅尔频率倒谱系数(MFCC)
  17. 使用grunt-init自动创建gruntfile.js和package.json文件
  18. centos 7安装mysql 执行./scripts/mysql_install_db --user=mysql 报错 FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db: Data::Dumper
  19. 架构(四)Git简介,安装以及相关命令SourceTree
  20. Latex(表格|图片(一丢丢))

热门文章

  1. input实时监听
  2. 每天进步一点点out1
  3. C++解析六-继承
  4. In-App Purchase iap 内付费 二次验证代码 (java 服务器端)
  5. Date和 Calendar
  6. 和的java程序
  7. FFT模板(无讲解)
  8. C++定义自己的异常
  9. 用Python的导入csv、文本文件、Excel文件的数据
  10. 不管你是否已经准备面试, 这45道Python面试题都对你非常有帮助!(mark!)