Skip to content

Commit 07dfbff

Browse files
authoredJul 11, 2023
Update 0069-sqrtx.js
Using the Bitwise operator to get the middle value.
1 parent a898b71 commit 07dfbff

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed
 

‎javascript/0069-sqrtx.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ var mySqrt = function(x) {
1111
let right = x;
1212

1313
while(left <= right) {
14-
const mid = left + Math.floor((right - left)/2);
14+
const mid = (left + right) >> 1;
1515
if(mid * mid <= x && (mid+1) * (mid+1) > x) return mid;
1616
if(mid * mid < x) {
1717
left = mid + 1;

0 commit comments

Comments
 (0)
Please sign in to comment.