Simple C++ solution with set


  • 0
    T

    Simple C++ solution with set

    class Solution {
    public:
        bool judgeSquareSum(int c) {
            set<int> s;
            int sqc = sqrt(c);
            for (int i = 0; i <= sqc; ++i) {
                s.insert(c - i*i);
                if (s.count(i*i)) return true;
            }
            return false;
        }
    };
    

Log in to reply
 

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