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. MySQL读写分离项目配置

    一.项目信息 1.拓扑 二.环境规划 1.主机信息 2.软件信息 3.MySQL中间件 三.配置

  2. 【安卓周记】笔记复习记录:No.2

    [安卓] 1. Activity横竖屏切换生命周期变化,分三种情况: 1. 没有配置android:configChanges:每次横竖屏切换都会重新走一遍生命周期 2. 配置android:conf ...

  3. Mysql 碎片整理与统计信息收集

    ======重新收集统计信息======= 1.分析和存储表的关键字分布 analyze table table_name; analyze 用于收集优化器的统计信息.和tuning相关:对 myis ...

  4. js之大文件断点续传

    文件夹上传:从前端到后端 文件上传是 Web 开发肯定会碰到的问题,而文件夹上传则更加难缠.网上关于文件夹上传的资料多集中在前端,缺少对于后端的关注,然后讲某个后端框架文件上传的文章又不会涉及文件夹. ...

  5. C变量作用域的分类和优先级

    变量从高到低的优先级以下面展示: 1.文件作用域:变量在全局从文件开头到结尾一直有效即全局变量 2.函数作用域也称局部变量 3.代码块作用域:用{}花括号内的定义的变量:都是在代码块{}中有效 如:i ...

  6. 洛谷 P2313 [HNOI2005]汤姆的游戏 题解

    P2313 [HNOI2005]汤姆的游戏 题目描述 汤姆是个好动的孩子,今天他突然对圆规和直尺来了兴趣.于是他开始在一张很大很大的白纸上画很多很多的矩形和圆.画着画着,一不小心将他的爆米花弄撒了,于 ...

  7. 解决tecplot中壁面速度不为0的问题

    当直接将fluent的.cas文件和.dat文件导入tecplot中进行后处理的时候,我们会发现,壁面速度不为0的情况(见上图). 出现这样问题的原因为:fluent的计算数据是存储在每个单元的中心位 ...

  8. SpringBoot 配置Druid:不显示SQL监控 —(*) property for user to setup

    题外话: SpringBoot整合Druid 请查看https://www.cnblogs.com/JealousGirl/p/druid.html Druid登录后数据源页面.SQL监控等不显示数据 ...

  9. Java-Maven(九):Maven 项目pom文件引入工程根目录下lib文件夹下的jar包

    由于项目一些特殊需求,pom依赖的包可能是非Maven Repository下的包文件,因此无法自己从网上下载.此时,我们团队git上对该jar使用. Maven项目pom引入lib下jar包 在ec ...

  10. MySQL两地三中心方案初步设计【转】

    整体内容会按照如下的方式来进行设计: 首先说下方案的背景,我参考了一些资料(参见附件). 方案背景 随着互联网业务快速发展,多IDC的业务支撑能力和要求也逐步提升,行业内的“两地三中心”方案较为流行. ...