0
点赞
收藏
分享

微信扫一扫

NC32 求平方根

witmy 2022-06-13 阅读 24

NC32 求平方根_整型
描述
实现函数 int sqrt(int x).
计算并返回 x 的平方根(向下取整)
NC32 求平方根_i++_02

示例1

输入:
2
返回值:
1
class Solution {
public:
/**
*
* @param x int整型
* @return int整型
*/
int sqrt(int x) {
// write code here
for(int i=0;i<=x;i++)
{
if((i*i)>x)
return i-1;
else if((i*i)==x)
return i;
}
return 1;

}
};


举报

相关推荐

0 条评论