LeetCode x 的平方根(Sqrt(x))

版权声明:本文为博主原创文章,转载时请在文章最前方附上本文地址。 https://blog.csdn.net/qq_35033270/article/details/81106904

题目

实现 int sqrt(int x) 函数。

计算并返回 x 的平方根,其中 x 是非负整数。

由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去。

示例
输入: 4
输出: 2

思路
利用math自带 函数

public int mySqrt(int x) {
       return (int)Math.sqrt(x);
        }

猜你喜欢

转载自blog.csdn.net/qq_35033270/article/details/81106904