Simple and easy solution 3 lines 0ms using Newton method C++


  • 0
    class Solution {
    public:
        bool isPerfectSquare(int num) 
        {
            long g = num;
            while(g*g > num)  g = (g+num/g)>>1;
            return g*g==num;
        }
    };

Log in to reply
 

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