File tree Expand file tree Collapse file tree 2 files changed +42
-0
lines changed
Algorithms/Sum of Square Numbers Expand file tree Collapse file tree 2 files changed +42
-0
lines changed Original file line number Diff line number Diff line change 1+ // Source : https://leetcode.com/problems/sum-of-square-numbers/description/
2+ // Author : Han Zichi
3+ // Date : 2017-07-29
4+
5+ /**
6+ * @param {number } c
7+ * @return {boolean }
8+ */
9+ var judgeSquareSum = function ( c ) {
10+ let mid = ~ ~ ( Math . sqrt ( c ) )
11+
12+ for ( let i = 0 ; i <= mid ; i ++ ) {
13+ let rem = c - i * i
14+ if ( rem === Math . pow ( ~ ~ Math . sqrt ( rem ) , 2 ) )
15+ return true
16+ }
17+
18+ return false
19+ } ;
Original file line number Diff line number Diff line change 1+ # Source : https://leetcode.com/problems/sum-of-square-numbers/description/
2+ # Author : Han Zichi
3+ # Date : 2017-07-29
4+
5+ import math
6+
7+ class Solution :
8+ def judgeSquareSum (self , c ):
9+ """
10+ :type c: int
11+ :rtype: bool
12+ """
13+ mid = math .floor (math .sqrt (c ))
14+
15+ for i in range (0 , mid + 1 ):
16+ rem = c - i * i
17+ if (rem == math .pow (math .floor (math .sqrt (rem )), 2 )):
18+ return True
19+
20+ return False
21+
22+ obj = Solution ()
23+ print (obj .judgeSquareSum (5 ))
You can’t perform that action at this time.
0 commit comments