[69] x 的平方根

This commit is contained in:
Wen 2023-04-26 10:33:26 +08:00
parent c7eafcfc21
commit d6bec608eb
1 changed files with 21 additions and 0 deletions

View File

@ -0,0 +1,21 @@
/*
* @lc app=leetcode.cn id=69 lang=javascript
*
* [69] x 的平方根
*/
// @lc code=start
/**
* @param {number} x
* @return {number}
*/
var mySqrt = function(x) {
let ret = 1;
while (ret * ret < x) {
ret += 1;
}
if (ret * ret > x) ret -= 1;
return ret;
};
// @lc code=end