{"id":196,"date":"2018-08-18T20:27:14","date_gmt":"2018-08-18T12:27:14","guid":{"rendered":"https:\/\/www.ccagml.com\/?p=196"},"modified":"2018-11-27T17:28:05","modified_gmt":"2018-11-27T09:28:05","slug":"283-move-zeroes","status":"publish","type":"post","link":"https:\/\/www.ccagml.com\/?p=196","title":{"rendered":"283. Move Zeroes"},"content":{"rendered":"<p>Given an array\u00a0<code>nums<\/code>, write a function to move all\u00a0<code>0<\/code>&#8216;s to the end of it while maintaining the relative order of the non-zero elements.<\/p>\n<p><b>Example:<\/b><\/p>\n<pre><b>Input:<\/b> <code>[0,1,0,3,12]<\/code> <b>Output:<\/b> <code>[1,3,12,0,0]<\/code><\/pre>\n<p><b>Note<\/b>:<\/p>\n<ol>\n<li>You must do this\u00a0<b>in-place<\/b>\u00a0without making a copy of the array.<\/li>\n<li>Minimize the total number of operations.<\/li>\n<\/ol>\n<p><strong>Python<\/strong><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\"> \r\nclass Solution(object):\r\n    def moveZeroes(self, nums):\r\n        &quot;&quot;&quot;\r\n        :type nums: List[int]\r\n        :rtype: void Do not return anything, modify nums in-place instead.\r\n        &quot;&quot;&quot;\r\n        num_len = len(nums)\r\n        try:\r\n            while True:\r\n                nums.remove(0)\r\n        except:\r\n            while len(nums) &lt; num_len:\r\n                nums.append(0)\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Given an array\u00a0nums, write a function to move all\u00a00&#038;#82<a href=\"https:\/\/www.ccagml.com\/?p=196\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">283. Move Zeroes<\/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\/196"}],"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=196"}],"version-history":[{"count":1,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/196\/revisions"}],"predecessor-version":[{"id":197,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/196\/revisions\/197"}],"wp:attachment":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}