欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

LeetCode69题

程序员文章站 2022-03-19 11:57:08
...

LeetCode69题

public static int mySqrta(int x) {
        int left = 0;
        int right = x;
        int ans = -1;
        int mid = left + (right - left) / 2;
        while (left <= right) {

            if ((long) mid * mid <= x) {
                ans = mid;
                left = mid + 1;
            } else {
                right = mid - 1;
            }
        }
        return ans;
    }
相关标签: LeetCode leetcode