leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

0633.cpp (375B)


      1 class Solution {
      2   public:
      3     bool judgeSquareSum(const int c) const {
      4         long left = 0, right = sqrt(c);
      5 
      6         while (left <= right) {
      7             const long mid = left * left + right * right;
      8             if (mid == c) return true;
      9             if (mid < c)
     10                 left++;
     11             else
     12                 right--;
     13         }
     14 
     15         return false;
     16     }
     17 };