LeetCode——Sqrt(x)

来源:互联网 发布:政策网络理论代表人物 编辑:程序博客网 时间:2024/05/16 10:12

Sqrt(x)


Implement int sqrt(int x).

Compute and return the square root of x.

Java代码:

public class Solution {    public int sqrt(int x) {        if(x ==0)return 0;        for(int i=1;i<46341;i++)        {            if(i*i == x)return i;            if(i*i>x)return i-1;        }        return 46340;    }}

 

0 0
原创粉丝点击