Very short and simple C++ solution


  • 0
    R
    class Solution {
    public:
        bool isPerfectSquare(int num) {
            int e = 1;
            while(num > 0) {
                num -= e;
                e += 2;
            }
            return num == 0;
        }
    };
    

Log in to reply
 

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