File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 477
477
628|[ Maximum Product of Three Numbers] ( ./0628-maximum-product-of-three-numbers.js ) |Easy|
478
478
629|[ K Inverse Pairs Array] ( ./0629-k-inverse-pairs-array.js ) |Hard|
479
479
630|[ Course Schedule III] ( ./0630-course-schedule-iii.js ) |Hard|
480
+ 633|[ Sum of Square Numbers] ( ./0633-sum-of-square-numbers.js ) |Medium|
480
481
637|[ Average of Levels in Binary Tree] ( ./0637-average-of-levels-in-binary-tree.js ) |Easy|
481
482
643|[ Maximum Average Subarray I] ( ./0643-maximum-average-subarray-i.js ) |Easy|
482
483
645|[ Set Mismatch] ( ./0645-set-mismatch.js ) |Medium|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * 633. Sum of Square Numbers
3
+ * https://leetcode.com/problems/sum-of-square-numbers/
4
+ * Difficulty: Medium
5
+ *
6
+ * Given a non-negative integer c, decide whether there're two integers a and b such
7
+ * that a2 + b2 = c.
8
+ */
9
+
10
+ /**
11
+ * @param {number } c
12
+ * @return {boolean }
13
+ */
14
+ var judgeSquareSum = function ( c ) {
15
+ for ( let left = 0 , right = Math . floor ( Math . sqrt ( c ) ) ; left <= right ; ) {
16
+ const sum = left * left + right * right ;
17
+ if ( sum === c ) return true ;
18
+ if ( sum < c ) left ++ ;
19
+ else right -- ;
20
+ }
21
+ return false ;
22
+ } ;
You can’t perform that action at this time.
0 commit comments