{"id":2161,"date":"2016-09-03T11:11:54","date_gmt":"2016-09-03T03:11:54","guid":{"rendered":"http:\/\/boweihe.me\/?p=2161"},"modified":"2016-09-03T11:11:54","modified_gmt":"2016-09-03T03:11:54","slug":"leetcode-50-powx-n","status":"publish","type":"post","link":"https:\/\/dayandcarrot.space\/?p=2161","title":{"rendered":"LeetCode 50. Pow(x, n)"},"content":{"rendered":"<p>\u8fb9\u754c\u68c0\u67e5\uff1a0\uff0cINT_MAX, INT_MIN<\/p>\n<pre class=\"lang:c++ decode:true \">class Solution {\nprivate:\n    map&lt;int, double&gt; memory;\npublic:\n    double myPow(double x, int n) {\n        if(n == 0)\n            return 1.0;\n        if(n == 1)\n            return x;\n        if(n == -1)\n            return 1\/x;\n        if(memory.count(n)&gt;0)\n            return memory[n];\n        double result = myPow(x, n\/2) * myPow(x, n\/2);\n        if(n%2 != 0){\n            result *= (n&lt;0)? 1\/x : x;\n        }\n        memory[n] = result;\n        return result;\n    }\n};<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fb9\u754c\u68c0\u67e5\uff1a0\uff0cINT_MAX, INT_MIN class Solution { private: map&lt;int, double&gt; memory; public: double myPow(double x, int n) { if(n == 0) return 1.0; if(n == 1) return x; if(n == -1) return 1\/x; if(memory.count(n)&gt;0) return memory[n]; double result = myPow(x, n\/2) * myPow(x, n\/2); if(n%2 != 0){ result *= (n&lt;0)? 1\/x : x; } memory[n] = result; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[66],"class_list":["post-2161","post","type-post","status-publish","format-standard","hentry","category-study","tag-leetcode-oj"],"_links":{"self":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/2161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2161"}],"version-history":[{"count":0,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=\/wp\/v2\/posts\/2161\/revisions"}],"wp:attachment":[{"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dayandcarrot.space\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}