{"id":188,"date":"2018-06-02T19:23:33","date_gmt":"2018-06-02T11:23:33","guid":{"rendered":"https:\/\/www.ccagml.com\/?p=188"},"modified":"2018-11-27T17:24:09","modified_gmt":"2018-11-27T09:24:09","slug":"231-power-of-two","status":"publish","type":"post","link":"https:\/\/www.ccagml.com\/?p=188","title":{"rendered":"231. Power of Two"},"content":{"rendered":"<p>Given an integer, write a function to determine if it is a power of two.<\/p>\n<p><strong>Example 1:<\/strong><\/p>\n<pre><strong>Input:<\/strong> 1\r\n<strong>Output:<\/strong> true \r\n<strong>Explanation: <\/strong>2<sup>0<\/sup>\u00a0= 1\r\n<\/pre>\n<p><strong>Example 2:<\/strong><\/p>\n<pre><strong>Input:<\/strong> 16\r\n<strong>Output:<\/strong> true\r\n<strong>Explanation: <\/strong>2<sup>4<\/sup>\u00a0= 16<\/pre>\n<p><strong>Example 3:<\/strong><\/p>\n<pre><strong>Input:<\/strong> 218\r\n<strong>Output:<\/strong> false<\/pre>\n<p><strong>Python<\/strong><\/p>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\"> \r\nclass Solution(object):\r\n    def isPowerOfTwo(self, n):\r\n        &quot;&quot;&quot;\r\n        :type n: int\r\n        :rtype: bool\r\n        &quot;&quot;&quot;\r\n        if n &lt; 0:\r\n            return False\r\n        a = str(bin(n)).replace(&quot;b&quot;, &quot;&quot;)\r\n        result = 0\r\n        for i in a:\r\n            result += int(i)\r\n        return True if result == 1 else False\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Given an integer, write a function to determine if it i<a href=\"https:\/\/www.ccagml.com\/?p=188\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">231. Power of Two<\/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\/188"}],"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=188"}],"version-history":[{"count":1,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/188\/revisions"}],"predecessor-version":[{"id":189,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=\/wp\/v2\/posts\/188\/revisions\/189"}],"wp:attachment":[{"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=188"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=188"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ccagml.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=188"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}