File tree 2 files changed +26
-0
lines changed 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 9
9
- Day 6: [ Majority Element] ( https://github.com/libterty/leetcode-challenge/blob/master/src/may/day-six/index.ts ) :relaxed :
10
10
- Day 7: [ Cousins in Binary Tree] ( https://github.com/libterty/leetcode-challenge/blob/master/src/may/day-seven/index.ts ) :hushed :
11
11
- Day 8: [ check Straight Line] ( https://github.com/libterty/leetcode-challenge/blob/master/src/may/day-eight/index.ts ) :grin :
12
+ - Day 9: [ Is Perfect Square] ( https://github.com/libterty/leetcode-challenge/blob/master/src/may/day-nine/index.ts ) :alien :
Original file line number Diff line number Diff line change
1
+ /*
2
+ *
3
+ * isPerfectSquare
4
+ * @param {number } num
5
+ * @return {boolean }
6
+ */
7
+
8
+ //Note: Do not use any built-in library function such as sqrt.
9
+ export const isPerfectSquare = function ( num : number ) : boolean {
10
+ if ( num === 0 ) return false ;
11
+ if ( num === 1 ) return true ;
12
+ let i : number = 1 ;
13
+ let result : number = 1 ;
14
+ while ( result < num ) {
15
+ i ++ ;
16
+ result = i * i ;
17
+ }
18
+ return result === num ;
19
+ } ;
20
+
21
+ const a = isPerfectSquare ( 16 ) ;
22
+ const b = isPerfectSquare ( 14 ) ;
23
+
24
+ console . log ( 'a' , a ) ;
25
+ console . log ( 'b' , b ) ;
You can’t perform that action at this time.
0 commit comments