Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit c04fc31

Browse files
committed
add day-nine
1 parent 90a7f93 commit c04fc31

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@
99
- Day 6: [Majority Element](https://github.com/libterty/leetcode-challenge/blob/master/src/may/day-six/index.ts) :relaxed:
1010
- Day 7: [Cousins in Binary Tree](https://github.com/libterty/leetcode-challenge/blob/master/src/may/day-seven/index.ts) :hushed:
1111
- 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:

src/may/day-nine/index.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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);

0 commit comments

Comments
 (0)