java 力扣 69 题 算术平方

class Solution {

    public int mySqrt(int x) {

      int left=0;

        int right=x-1;

        int ans=-1;

        if (x == 0 || x==1) return x;

        while (left<=right){

            int mid=(left+right)>>>1;

            if ((long)mid*mid<= x) {

                ans = mid;

                left=mid+1;

            }

            else{

                right=mid-1;

            }

        }

        return ans;

        }

}

你可能感兴趣的:(算法,数据结构,java)