{"id":3660,"date":"2018-08-22T08:22:29","date_gmt":"2018-08-22T15:22:29","guid":{"rendered":"https:\/\/zxi.mytechroad.com\/blog\/?p=3660"},"modified":"2018-08-22T08:28:59","modified_gmt":"2018-08-22T15:28:59","slug":"leetcode-633-sum-of-square-numbers","status":"publish","type":"post","link":"https:\/\/zxi.mytechroad.com\/blog\/uncategorized\/leetcode-633-sum-of-square-numbers\/","title":{"rendered":"\u82b1\u82b1\u9171 LeetCode 633. Sum of Square Numbers"},"content":{"rendered":"<p><iframe loading=\"lazy\" title=\"\u82b1\u82b1\u9171 LeetCode 633. Sum of Square Numbers - \u5237\u9898\u627e\u5de5\u4f5c EP17\" width=\"500\" height=\"375\" src=\"https:\/\/www.youtube.com\/embed\/2tiZMMTt-CQ?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe><\/p>\n<h1><strong>Problem<\/strong><\/h1>\n<p>Given a non-negative integer\u00a0<code>c<\/code>, your task is to decide whether there&#8217;re two integers\u00a0<code>a<\/code>\u00a0and\u00a0<code>b<\/code>\u00a0such that a<sup>2<\/sup>\u00a0+ b<sup>2<\/sup>\u00a0= c.<\/p>\n<p><b>Example 1:<\/b><\/p>\n<pre class=\"crayon:false\"><b>Input:<\/b> 5\r\n<b>Output:<\/b> True\r\n<b>Explanation:<\/b> 1 * 1 + 2 * 2 = 5\r\n<\/pre>\n<p><b>Example 2:<\/b><\/p>\n<pre class=\"crayon:false\"><b>Input:<\/b> 3\r\n<b>Output:<\/b> False\r\n<\/pre>\n<h1><strong>Solution: Math<\/strong><\/h1>\n<p>Time complexity: O(sqrt(c))<\/p>\n<p>Space complexity: O(1)<\/p>\n<pre class=\"lang:c++ decode:true  \">\/\/ Author: Huahua\r\n\/\/ Running time: 4 ms\r\nclass Solution {\r\npublic:\r\n  bool judgeSquareSum(int c) {\r\n    int m = sqrt(c);\r\n    for (int a = 0; a &lt;= m; ++a) {\r\n      int b = round(sqrt(c - a * a));\r\n      if (a * a + b * b == c) return true;\r\n    }\r\n    return false;\r\n  }\r\n};<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Problem Given a non-negative integer\u00a0c, your task is to decide whether there&#8217;re two integers\u00a0a\u00a0and\u00a0b\u00a0such that a2\u00a0+ b2\u00a0= c. Example 1: Input: 5 Output: True Explanation:&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[222,31,61],"class_list":["post-3660","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-easy","tag-math","tag-sqrt","entry","simple"],"_links":{"self":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/3660","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/comments?post=3660"}],"version-history":[{"count":4,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/3660\/revisions"}],"predecessor-version":[{"id":3664,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/posts\/3660\/revisions\/3664"}],"wp:attachment":[{"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/media?parent=3660"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/categories?post=3660"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/zxi.mytechroad.com\/blog\/wp-json\/wp\/v2\/tags?post=3660"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}