{"id":190,"date":"2018-06-03T21:24:33","date_gmt":"2018-06-03T13:24:33","guid":{"rendered":"https:\/\/www.ccagml.com\/?p=190"},"modified":"2018-11-27T17:25:05","modified_gmt":"2018-11-27T09:25:05","slug":"198-house-robber","status":"publish","type":"post","link":"https:\/\/www.ccagml.com\/?p=190","title":{"rendered":"198. House Robber"},"content":{"rendered":"<p>You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and\u00a0<b>it will automatically contact the police if two adjacent houses were broken into on the same night<\/b>.<\/p>\n<p>Given a list of non-negative integers representing the amount of money of each house, determine the maximum amount of money you can rob tonight\u00a0<b>without alerting the police<\/b>.<\/p>\n<p><strong>Example 1:<\/strong><\/p>\n<pre><strong>Input:<\/strong> [1,2,3,1]\r\n<strong>Output:<\/strong> 4\r\n<strong>Explanation:<\/strong> Rob house 1 (money = 1) and then rob house 3 (money = 3).\r\n\u00a0            Total amount you can rob = 1 + 3 = 4.<\/pre>\n<p><strong>Example 2:<\/strong><\/p>\n<pre><strong>Input:<\/strong> [2,7,9,3,1]\r\n<strong>Output:<\/strong> 12\r\n<strong>Explanation:<\/strong> Rob house 1 (money = 2), rob house 3 (money = 9) and rob house 5 (money = 1).\r\n\u00a0            Total amount you can rob = 2 + 9 + 1 = 12.<\/pre>\n<p><strong>Python<\/strong><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\"> \r\nclass Solution(object):\r\n    def rob(self, nums):\r\n        &quot;&quot;&quot;\r\n        :type nums: List[int]\r\n        :rtype: int\r\n        &quot;&quot;&quot;\r\n        self.nums = nums\r\n        if len(nums) == 0:\r\n            return 0\r\n        if len(nums) == 1:\r\n            return nums[0]\r\n\r\n        self.y = [0 for i in range(len(nums))]\r\n        for a in range(len(nums)):\r\n            self.get_sum(a)\r\n        return max(self.y)\r\n\r\n    def get_sum(self, a):\r\n        self.y[0] = self.nums[0]\r\n        self.y[1] = max(self.y[0], self.nums[1])\r\n        if a &gt; 1:\r\n            self.y[a] = max(self.y[a - 1], self.y[a - 2] + self.nums[a])\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>You are a professional robber planning to rob houses al<a href=\"https:\/\/www.ccagml.com\/?p=190\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">198. House Robber<\/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\/190"}],"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=190"}],"version-history":[{"count":1,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/190\/revisions"}],"predecessor-version":[{"id":191,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/190\/revisions\/191"}],"wp:attachment":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=190"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=190"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=190"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}