最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

leetcode 888.Fair Candy Swap

2022-02-14 15:03 作者:您是打尖兒還是住店呢  | 我要投稿

Alice and bob have a different total number of candies. You are given two integer arrays??and??where??is the number of candies of the??box of candy that Alice has and??is the number of candies of the??box of candy that bob has.

Since they are friends, they would like to exchange one candy box 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 number of candies in each box they have.

Return an integer array??where??is the number of candies in the box that Alice must exchange, and??is the number of candies in the box that bob must exchange. If there are multiple answers, you may?return any?one of them. It is guaranteed that at least one answer exists.

?

Example 1:

Input: aliceSizes = [1,1], bobSizes = [2,2]Output: [1,2]

Example 2:

Input: aliceSizes = [1,2], bobSizes = [2,3]Output: [1,2]

Example 3:

Input: aliceSizes = [2], bobSizes = [1,3]Output: [2,3]

?

Constraints:

  • Alice and bob have a different total number of candies.

  • There will be at least one valid answer for the given input.

很好解釋,因為只能交換一次,那么2個人糖果總和的差異,肯定是交換時候那個糖果數(shù)量差異的2倍。所以2個for循環(huán)就可以了。

思路有了,code就簡單些了。

Runtime:?1281 ms, faster than?5.08%?of?Java?online submissions for?Fair Candy Swap.

Memory Usage:?63.3 MB, less than?42.30%?of?Java?online submissions for?Fair Candy Swap.

Next challenges:

Maximum Candies You Can Get from BoxesMaximum Performance of a TeamMaximum Erasure Value


leetcode 888.Fair Candy Swap的評論 (共 條)

分享到微博請遵守國家法律
鄯善县| 稷山县| 霍城县| 平南县| 河西区| 云林县| 堆龙德庆县| 武山县| 禄丰县| 祁东县| 西充县| 龙江县| 渝北区| 连云港市| 斗六市| 闵行区| 吉隆县| 庆阳市| 安徽省| 华亭县| 天镇县| 丹寨县| 宝山区| 上杭县| 尼玛县| 台安县| 洞口县| 郸城县| 固阳县| 威海市| 武乡县| 新乡市| 沽源县| 南昌县| 文成县| 驻马店市| 龙海市| 水城县| 华亭县| 广东省| 彩票|