561. Array Partition I
❀ Origin
Problem
Given an array of 2n integers, your task is to group these integers into n pairs of integer,
say (a1, b1), (a2, b2), …, (an, bn), which makes sum of min(ai, bi) for all i from 1 to n as large as possible.
Note
- n is a positive integer, which is in the range of [1, 10000].
- All the integers in the array will be in the range of [-10000, 10000].
Example 1
1 | Input: [1,4,3,2] |
❀ 翻譯
問題
給定一個 2n 個整數的陣列, 你的任務是將這些整數分成 n 組一對的整數,
譬如 (a1, b1), (a2, b2), …, (an, bn), 並且這些 i 的整數對的 min(ai, bi) 的總和要盡可能的大.
注意
- n 是一個正整數, 其範圍在 [1, 10000].
- 所有在陣列中的整數, 其範圍在 [-10000, 10000].
❀ Solution
JavaScript
1 | /** |