LeetCode 0367 - Valid Perfect Square

2021-08-11 11:20:49 浏览数 (1)

Valid Perfect Square

Desicription

Given a positive integer num, write a function which returns True if num is a perfect square else False.

Note: Do not use any built-in library function such as sqrt.

Example 1:

代码语言:javascript复制
Input: 16
Output: true

Example 2:

代码语言:javascript复制
Input: 14
Output: false

Solution

代码语言:javascript复制
class Solution {
public:
    bool isPerfectSquare(int num) {
        return int(pow(int(sqrt(num)), 2.0)) == num;
    }
};

0 人点赞