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 aft…
这是悦乐书的第339次更新,第363篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第208题(顺位题号是888).Alice和Bob有不同大小的糖果棒:A[i]是Alice拥有的第i个糖果棒的大小,B[j]是Bob拥有的第j个糖果棒的大小. 由于他们是朋友,他们想交换一个糖果,以便交换后,他们都有相同的糖果总量. (一个人拥有的糖果总量是他们拥有的糖果大小的总和.) 返回一个整数数组ans,其中ans[0]是Alice必须交换的糖果的大小,ans[1]是Bob必须交…
来源:力扣(LeetCode) 链接:https://leetcode.cn/problems/fair-candy-swap 著作权归领扣网络所有.商业转载请联系官方授权,非商业转载请注明出处. 假设爱丽丝的i盒糖果和鲍勃的j盒糖果已按糖果数量有序排列,aliceSizes[i]<aliceSizes[i+1] bobSizes[j]<bobSizes[j+1] 任取爱丽丝的一盒糖果aliceSizes[x],是否一定会有一盒糖果与之对应?(交换这样的两盒糖果后,两人的糖果数量相同) 一定会…
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 aft…
problem 888. Fair Candy Swap solution: class Solution { public: vector<int> fairCandySwap(vector<int>& A, vector<int>& B) { , sumB = , delta = ; unordered_set<int> setA; for(auto a:A) { sumA += a; setA.insert(a);//err... }…
作者: 负雪明烛 id: fuxuemingzhu 个人公众号: 每日算法题 本文关键词:力扣,LeetCode,算法题,算法,Python 目录 题目描述 题目大意 解题方法 代码 刷题心得 关于作者 日期 题目地址:https://leetcode.com/problems/fair-candy-swap/description/ 题目描述 Alice and Bob have candy bars of different sizes: A[i] is the size of the i-…
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 aft…
问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3758 访问. 爱丽丝和鲍勃有不同大小的糖果棒:A[i] 是爱丽丝拥有的第 i 块糖的大小,B[j] 是鲍勃拥有的第 j 块糖的大小. 因为他们是朋友,所以他们想交换一个糖果棒,这样交换后,他们都有相同的糖果总量.(一个人拥有的糖果总量是他们拥有的糖果棒大小的总和.) 返回一个整数数组 ans,其中 ans[0] 是爱丽丝必须交换的糖果棒的大小,ans[1] 是…
爱丽丝和鲍勃有不同大小的糖果棒:A[i] 是爱丽丝拥有的第 i 块糖的大小,B[j] 是鲍勃拥有的第 j 块糖的大小. 因为他们是朋友,所以他们想交换一个糖果棒,这样交换后,他们都有相同的糖果总量.(一个人拥有的糖果总量是他们拥有的糖果棒大小的总和.) 返回一个整数数组 ans,其中 ans[0] 是爱丽丝必须交换的糖果棒的大小,ans[1] 是 Bob 必须交换的糖果棒的大小. 如果有多个答案,你可以返回其中任何一个.保证答案存在. 示例 1: 输入:A = [1,1], B = [2,2]…
题目要求 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 tha…