五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

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

分享到微博請遵守國家法律
乌什县| 奎屯市| 河北区| 于都县| 高安市| 来宾市| 温泉县| 百色市| 大港区| 论坛| 涿州市| 新巴尔虎左旗| 金华市| 崇州市| 鄂托克前旗| 灵寿县| 凌海市| 锡林浩特市| 楚雄市| 尼木县| 沐川县| 凤山县| 迁西县| 汉阴县| 安乡县| 上栗县| 兴和县| 陇川县| 永丰县| 安泽县| 洛扎县| 贺州市| 安塞县| 阳新县| 辽源市| 景宁| 自治县| 婺源县| 道真| 芦溪县| 济宁市|