Simple C++ using math

  • -5
    class Solution {
        bool isPerfectSquare(int num) {
            if(num <= 0)return false;
            int sq = sqrt(num);
            return (sq*sq == num);

  • 0

    Obviously, with sqrt, the question looks trivial.
    You should not use it.

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

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.