File tree 2 files changed +31
-0
lines changed
2 files changed +31
-0
lines changed Original file line number Diff line number Diff line change 127
127
347|[ Top K Frequent Elements] ( ./0347-top-k-frequent-elements.js ) |Medium|
128
128
349|[ Intersection of Two Arrays] ( ./0349-intersection-of-two-arrays.js ) |Easy|
129
129
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|
130
131
374|[ Guess Number Higher or Lower] ( ./0374-guess-number-higher-or-lower.js ) |Medium|
131
132
383|[ Ransom Note] ( ./0383-ransom-note.js ) |Easy|
132
133
387|[ First Unique Character in a String] ( ./0387-first-unique-character-in-a-string.js ) |Easy|
Original file line number Diff line number Diff line change
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
+ } ;
You can’t perform that action at this time.
0 commit comments