Skip to content

Commit a0f30dc

Browse files
committed
Add solution #367
1 parent a1074c8 commit a0f30dc

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

README.md

+1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
347|[Top K Frequent Elements](./0347-top-k-frequent-elements.js)|Medium|
128128
349|[Intersection of Two Arrays](./0349-intersection-of-two-arrays.js)|Easy|
129129
350|[Intersection of Two Arrays II](./0350-intersection-of-two-arrays-ii.js)|Easy|
130+
367|[Valid Perfect Square](./0367-valid-perfect-square.js)|Easy|
130131
374|[Guess Number Higher or Lower](./0374-guess-number-higher-or-lower.js)|Medium|
131132
383|[Ransom Note](./0383-ransom-note.js)|Easy|
132133
387|[First Unique Character in a String](./0387-first-unique-character-in-a-string.js)|Easy|
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* 367. Valid Perfect Square
3+
* https://leetcode.com/problems/valid-perfect-square/
4+
* Difficulty: Easy
5+
*
6+
* Given a positive integer num, return true if num is a perfect square or false otherwise.
7+
*
8+
* A perfect square is an integer that is the square of an integer. In other words, it is the
9+
* product of some integer with itself.
10+
*
11+
* You must not use any built-in library function, such as sqrt.
12+
*/
13+
14+
/**
15+
* @param {number} num
16+
* @return {boolean}
17+
*/
18+
var isPerfectSquare = function(num) {
19+
let i = 1;
20+
21+
while (num > 0) {
22+
num -= i;
23+
i += 2;
24+
if (num === 0) {
25+
return true;
26+
}
27+
}
28+
29+
return false;
30+
};

0 commit comments

Comments
 (0)