package LeetCode.contact;
//sqrt(x)
class Solution_69 {
public int mySqrt(int x) {
for(long i = 0; i < 999999; i++){
double y = i*i; //防止越界,所以这里使用double
double z = (i+1)*(i+1);
if(y <= x && x <z){
return (int)i;
}
}
return -1;
}
}
public class leetcode_69 {
public static void main(String[] args){
int x =2147483647;
// int x = 19;
Solution_69 sol = new Solution_69();
int a = sol.mySqrt(x);
System.out.println(a);
}
}
LeetCode_69:Sqrt(x) : Java
最新推荐文章于 2024-08-18 21:21:11 发布