{"id":224,"date":"2018-09-13T19:42:26","date_gmt":"2018-09-13T11:42:26","guid":{"rendered":"https:\/\/www.ccagml.com\/?p=224"},"modified":"2018-11-29T14:43:17","modified_gmt":"2018-11-29T06:43:17","slug":"832-flipping-an-image","status":"publish","type":"post","link":"https:\/\/www.ccagml.com\/?p=224","title":{"rendered":"832. Flipping an Image"},"content":{"rendered":"<p>Given a binary matrix\u00a0<code>A<\/code>, we want to flip the image horizontally, then invert it, and return the resulting image.<\/p>\n<p>To flip an image horizontally means that each row of the image is reversed.\u00a0 For example, flipping\u00a0<code>[1, 1, 0]<\/code>\u00a0horizontally results in\u00a0<code>[0, 1, 1]<\/code>.<\/p>\n<p>To invert an image means\u00a0that each\u00a0<code>0<\/code>\u00a0is replaced by\u00a0<code>1<\/code>, and each\u00a0<code>1<\/code>\u00a0is replaced by\u00a0<code>0<\/code>.\u00a0For example, inverting\u00a0<code>[0, 1, 1]<\/code>\u00a0results in\u00a0<code>[1, 0, 0]<\/code>.<\/p>\n<p><strong>Example 1:<\/strong><\/p>\n<pre><strong>Input: <\/strong>[[1,1,0],[1,0,1],[0,0,0]]\r\n<strong>Output: <\/strong>[[1,0,0],[0,1,0],[1,1,1]]\r\n<strong>Explanation:<\/strong> First reverse each row: [[0,1,1],[1,0,1],[0,0,0]].\r\nThen, invert the image: [[1,0,0],[0,1,0],[1,1,1]]\r\n<\/pre>\n<p><strong>Example 2:<\/strong><\/p>\n<pre><strong>Input: <\/strong>[[1,1,0,0],[1,0,0,1],[0,1,1,1],[1,0,1,0]]\r\n<strong>Output: <\/strong>[[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]\r\n<strong>Explanation:<\/strong> First reverse each row: [[0,0,1,1],[1,0,0,1],[1,1,1,0],[0,1,0,1]].\r\nThen invert the image: [[1,1,0,0],[0,1,1,0],[0,0,0,1],[1,0,1,0]]\r\n<\/pre>\n<p><strong>Notes:<\/strong><\/p>\n<ul>\n<li><code>1 &lt;= A.length = A[0].length &lt;= 20<\/code><\/li>\n<li><code>0 &lt;= A[i][j]<span style=\"font-family: sans-serif, Arial, Verdana, Trebuchet MS;\">\u00a0&lt;=\u00a0<\/span>1<\/code><\/li>\n<\/ul>\n<p><strong>Python<\/strong><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\"> \r\nclass Solution(object):\r\n    def flipAndInvertImage(self, A):\r\n        &quot;&quot;&quot;\r\n        :type A: List[List[int]]\r\n        :rtype: List[List[int]]\r\n        &quot;&quot;&quot;\r\n        r =[]\r\n        for a in A:\r\n            r_list = []\r\n            for i in a[::-1]:\r\n                r_list.append(int(i is not 1))\r\n            r.append(r_list)\r\n        return r\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Given a binary matrix\u00a0A, we want to flip the image hori<a href=\"https:\/\/www.ccagml.com\/?p=224\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">832. Flipping an Image<\/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\/224"}],"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=224"}],"version-history":[{"count":1,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/224\/revisions"}],"predecessor-version":[{"id":225,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/224\/revisions\/225"}],"wp:attachment":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=224"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=224"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=224"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}