[力扣] 算法 367 (C#)

367. 有效的完全平方数

public class Solution {
    public bool IsPerfectSquare(int num) {
        var min = 1;
        var max = 46340;
        while (min < max)
        {
            var mid = (min + max) / 2;
            if (num == mid * mid)
                return true;
            if (num > mid * mid)
                min = mid + 1;
            else
                max = mid - 1;
        }
        return num == min * max;
    }
}

发表评论