problem

888. Fair Candy Swap

solution:

class Solution {
public:
vector<int> fairCandySwap(vector<int>& A, vector<int>& B) {
int sumA = , sumB = , delta = ;
unordered_set<int> setA;
for(auto a:A)
{
sumA += a;
setA.insert(a);//err...
}
for(auto b:B) sumB += b;
delta = (sumA-sumB)/;
for(auto b:B)
{
if(setA.count(delta+b)) return {delta+b, b};
}
return vector<int>();
}
};

参考

1. Leetcode_easy_888. Fair Candy Swap;

2. discuss;

3. grandyang;

【Leetcode_easy】888. Fair Candy Swap的更多相关文章

  1. 【LeetCode】888. Fair Candy Swap 公平的糖果棒交换(Python)

    作者: 负雪明烛 id: fuxuemingzhu 个人公众号: 每日算法题 本文关键词:力扣,LeetCode,算法题,算法,Python 目录 题目描述 题目大意 解题方法 代码 刷题心得 关于作 ...

  2. 888. Fair Candy Swap@python

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

  3. [LeetCode] 888. Fair Candy Swap 公平糖果交换

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

  4. LeetCode 888 Fair Candy Swap 解题报告

    题目要求 Alice and Bob have candy bars of different sizes: A[i] is the size of the i-th bar of candy tha ...

  5. [LeetCode&Python] Problem 888. Fair Candy Swap

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

  6. LeetCode 888. Fair Candy Swap(C++)

    题目: Alice and Bob have candy bars of different sizes: A[i] is the size of the i-th bar of candy that ...

  7. LeetCode.888-公平的糖果交换(Fair Candy Swap)

    这是悦乐书的第339次更新,第363篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第208题(顺位题号是888).Alice和Bob有不同大小的糖果棒:A[i]是Alic ...

  8. C#LeetCode刷题之#888-公平的糖果交换(Fair Candy Swap)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3758 访问. 爱丽丝和鲍勃有不同大小的糖果棒:A[i] 是爱丽丝 ...

  9. [Swift]LeetCode888. 公平的糖果交换 | Fair Candy Swap

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

随机推荐

  1. Kubernetes 学习12 kubernetes 存储卷

    一.概述 1.我们此前讲过根据应用本身是否需要持久存储数据以及某一次请求和之前的请求是否有联系,可以分为四类应用 a.有状态,要存储 b.有状态,无持久存储 c.无状态,要存储 d.无状态,无持久存储 ...

  2. Luogu5591 小猪佩奇学数学 【单位根反演】

    题目链接:洛谷 \[ Ans=\frac{1}{k}(\sum_{i=0}^n\binom{n}{i}p^ii-\sum_{i=0}^n\binom{n}{i}p^i(i \ \mathrm{mod} ...

  3. 【一起来烧脑】读懂Promise知识体系

    知识体系 Promise基础语法,如何处理错误,简单介绍异步函数 内容 错误处理的两种方式: reject('错误信息').then(null, message => {}) throw new ...

  4. laravel 多控制器路由

    laravel 路由: ======================================= 公司的情况很不乐观...... 破产清算随时可能发生......

  5. 《挑战30天C++入门极限》新手入门:C++中布尔类型

        新手入门:C++中布尔类型 布尔类型对象可以被赋予文字值true或者false,所对应的关系就是真与假的概念. 我们通常使用的方法是利用他来判断条件的真与假,例如下面的代码: #include ...

  6. 坑:jmeter代理服务器录制脚本出现target controller is configured to "use recording Controller" but no such controller exists...

    配置好代理服务器后,运行代理服务器 run 报错: target controller is configured to "use recording Controller" bu ...

  7. sudo 命令

    su命令和su -命令最大的本质区别就是: 前者只是切换了root身份,但Shell环境仍然是普通用户的Shell: 而后者连用户和Shell环境一起切换成root身份了.只有切换了Shell环境才不 ...

  8. Java8 LocalDateTime的补充工具方法

    import java.time.*;import java.time.format.DateTimeFormatter;import java.time.format.DateTimeFormatt ...

  9. Docker理论简答

    Docker理论简答: 1.        介绍对docker的认识(10分) Docker是容器,容器不是docker Dockers就是一个文件夹,它欺骗操作系统说自己是一个操作系统,然后把所需要 ...

  10. kubernetes入门学习系列

    一.kubernetes基础概念 初识kubernetes kubernetes相关概念 二.kubernets架构和组件 kubernetes架构 kubernetes单Master架构 kuber ...