{"id":236,"date":"2018-11-14T19:47:58","date_gmt":"2018-11-14T11:47:58","guid":{"rendered":"https:\/\/www.ccagml.com\/?p=236"},"modified":"2018-11-29T14:48:37","modified_gmt":"2018-11-29T06:48:37","slug":"561-array-partition-i","status":"publish","type":"post","link":"https:\/\/www.ccagml.com\/?p=236","title":{"rendered":"561. Array Partition I"},"content":{"rendered":"<p>Given an array of\u00a0<b>2n<\/b>\u00a0integers, your task is to group these integers into\u00a0<b>n<\/b>\u00a0pairs of integer, say (a<sub>1<\/sub>, b<sub>1<\/sub>), (a<sub>2<\/sub>, b<sub>2<\/sub>), &#8230;, (a<sub>n<\/sub>, b<sub>n<\/sub>) which makes sum of min(a<sub>i<\/sub>, b<sub>i<\/sub>) for all i from 1 to n as large as possible.<\/p>\n<p><b>Example 1:<\/b><\/p>\n<pre><b>Input:<\/b> [1,4,3,2]\r\n\r\n<b>Output:<\/b> 4\r\n<b>Explanation:<\/b> n is 2, and the maximum sum of pairs is 4 = min(1, 2) + min(3, 4).\r\n<\/pre>\n<p><b>Note:<\/b><\/p>\n<ol>\n<li><b>n<\/b>\u00a0is a positive integer, which is in the range of [1, 10000].<\/li>\n<li>All the integers in the array will be in the range of [-10000, 10000].<\/li>\n<\/ol>\n<p><strong>Python<\/strong><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\"> \r\nclass Solution(object):\r\n    def arrayPairSum(self, nums):\r\n        &quot;&quot;&quot;\r\n        :type nums: List[int]\r\n        :rtype: int\r\n        &quot;&quot;&quot;\r\n        nums.sort()\r\n        return sum([v for k,v in enumerate(nums) if k%2==0])\r\n        \r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Given an array of\u00a02n\u00a0integers, your task is to group th<a href=\"https:\/\/www.ccagml.com\/?p=236\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">561. Array Partition I<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[29,20],"tags":[],"_links":{"self":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/236"}],"collection":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=236"}],"version-history":[{"count":1,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/236\/revisions"}],"predecessor-version":[{"id":237,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/236\/revisions\/237"}],"wp:attachment":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}