首页 > 代码库 > leetcode367

leetcode367

public class Solution {
    public bool IsPerfectSquare(int num) {
        int low = 1, high = num;
            while (low <= high)
            {
                long mid = (low + high) >> 1;
                if (mid * mid == num)
                {
                    return true;
                }
                else if (mid * mid < num)
                {
                    low = (int)mid + 1;
                }
                else
                {
                    high = (int)mid - 1;
                }
            }
            return false;
    }
}

https://leetcode.com/problems/valid-perfect-square/#/description

leetcode367