国产精品天干天干,亚洲毛片在线,日韩gay小鲜肉啪啪18禁,女同Gay自慰喷水

歡迎光臨散文網(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的評論 (共 條)

分享到微博請遵守國家法律
红原县| 旬阳县| 刚察县| 明水县| 衡南县| 宁津县| 旌德县| 万年县| 冷水江市| 禹州市| 清新县| 大邑县| 靖边县| 紫云| 秦安县| 莱阳市| 山东| 阿克陶县| 沅陵县| 阜宁县| 民勤县| 辛集市| 红桥区| 陵水| 苗栗县| 涪陵区| 岱山县| 怀化市| 上饶市| 宽城| 青龙| 巫山县| 湾仔区| 仁布县| 兰溪市| 万盛区| 达拉特旗| 乌鲁木齐县| 曲水县| 文昌市| 临桂县|