Finding pairs in O(n) time

programming
Tags: #<Tag:0x00007f242dfc4c18>

#1
vector<vector<int> > Solution::squareSum(int A) {
vector<vector<int> > ans;
for (int a = 1; a * a < A; a++) {
    float b = sqrt(A - a*a);
    if((int)b >= a)
    {
        if(b == (int)b)
        {
            vector < int > newEntry;
            newEntry.push_back(a);
            newEntry.push_back(b);
            ans.push_back(newEntry);
        }
    }
}
return ans;

}