File tree 2 files changed +28
-0
lines changed
2 files changed +28
-0
lines changed Original file line number Diff line number Diff line change 82
82
| 344| [ 反转字符串] ( https://leetcode-cn.com/problems/reverse-string/ ) | [ JavaScript] ( ./algorithms/reverse-string.js ) | Easy|
83
83
| 349| [ 两个数组的交集] ( https://leetcode-cn.com/problems/intersection-of-two-arrays/ ) | [ JavaScript] ( ./algorithms/intersection-of-two-arrays.js ) | Easy|
84
84
| 350| [ 两个数组的交集 II] ( https://leetcode-cn.com/problems/intersection-of-two-arrays-ii/ ) | [ JavaScript] ( ./algorithms/intersection-of-two-arrays-ii.js ) | Easy|
85
+ | 367| [ 有效的完全平方数] ( https://leetcode.cn/problems/valid-perfect-square/ ) | [ JavaScript] ( ./algorithms/valid-perfect-square.js ) | Easy|
85
86
| 383| [ 赎金信] ( https://leetcode.cn/problems/ransom-note/ ) | [ JavaScript] ( ./algorithms/ransom-note.js ) | Easy|
86
87
| 387| [ 字符串中的第一个唯一字符] ( https://leetcode-cn.com/problems/first-unique-character-in-a-string/ ) | [ JavaScript] ( ./algorithms/first-unique-character-in-a-string.js ) | Easy|
87
88
| 389| [ 找不同] ( https://leetcode.cn/problems/find-the-difference/ ) | [ JavaScript] ( ./algorithms/find-the-difference.js ) | Easy|
Original file line number Diff line number Diff line change
1
+ /**
2
+ * @param {number } num
3
+ * @return {boolean }
4
+ */
5
+ var isPerfectSquare = function ( num ) {
6
+ let left = 1 ;
7
+ let right = num ;
8
+
9
+ // num = 9
10
+ // 1 9 mid = 5
11
+ // 1 4 mid = 2
12
+ // 3 4 mid = 3
13
+
14
+ while ( left <= right ) {
15
+ let mid = Math . floor ( ( left + right ) / 2 ) ;
16
+
17
+ if ( mid * mid < num ) {
18
+ left = mid + 1 ;
19
+ } else if ( mid * mid > num ) {
20
+ right = mid - 1 ;
21
+ } else {
22
+ return true ;
23
+ }
24
+ }
25
+
26
+ return false ;
27
+ } ;
You can’t perform that action at this time.
0 commit comments