LeetCode第633題_Sum of Square Numbers

Given a non-negative integer c , your task is to decide whether there're two integers a and b such that a 2 + b 2 = c. Example 1: Input: 5 Output: True Explanation: 1 * 1 + 2 * 2 = 5 Example 2: Input: 3 Output: False 題目就是給定一個數輸入 判定是不是某兩個數的平方和 就是如此 1 -> 0^2 + 1^2 =1 -> true 2-> 1^2 + 1^2 = 2 -> true ... 3 -> x 4-> 0^2+2^2 = 4 ->true 第一版.直觀法(暴力法) 使用兩層迴圈去跑 範圍皆從0跑到該數 利用演算法【奇數之平方和必為一可開平方數】 圖像理解(正方形的邊) 所以改寫至程式進行算法優化後 原本輸入9 我的作法是給其跑兩層迴圈 i從0到9 j從0到9 ------------------------------- i=0時 j=0,j=1,j=2.......j=9給個都去跑 . . . i=9時 j=0,j=1,j=2.......j=9 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the edito...