Leetcode|Leetcode 367. Valid Perfect Square

【Leetcode|Leetcode 367. Valid Perfect Square】文章作者:Tyan
博客:noahsnail.com|CSDN|
1. Description Leetcode|Leetcode 367. Valid Perfect Square
文章图片
Valid Perfect Square 2. Solution

class Solution { public: bool isPerfectSquare(int num) { int left = 0; int right = num; while(left <= right) { long mid = (left + right) / 2; long square = mid * mid; if(square == num) { return true; } if(square > num) { right = mid - 1; } else { left = mid + 1; } } return false; } };

Reference
  1. https://leetcode.com/problems/valid-perfect-square/description/

    推荐阅读