Skip to content

Commit

Permalink
Merge pull request neetcode-gh#1372 from FahadulShadhin/valid_perfect…
Browse files Browse the repository at this point in the history
…_square

Adding 367-Valid-Perfect-Square.js
  • Loading branch information
Ahmad-A0 authored Nov 2, 2022
2 parents 2d1c14a + 0223d8a commit f39f20f
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions javascript/367-Valid-Perfect-Square.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @param {number} num
* @return {boolean}
*/
var isPerfectSquare = function(num) {
let left = 1, right = num;

while(left <= right) {
let mid = Math.floor((left + right) / 2);

if(mid*mid === num) return true;
else if(mid*mid > num) right = mid -1;
else left = mid + 1;
}

return false;
};

0 comments on commit f39f20f

Please sign in to comment.