Leetcode|Leetcode 367. Valid Perfect Square
【Leetcode|Leetcode 367. Valid Perfect Square】文章作者:Tyan
博客:noahsnail.com|CSDN|
1. Description
文章图片
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
- https://leetcode.com/problems/valid-perfect-square/description/
推荐阅读
- 【Leetcode/Python】001-Two|【Leetcode/Python】001-Two Sum
- leetcode|leetcode 92. 反转链表 II
- 解决SyntaxError:|解决SyntaxError: invalid syntax
- 二叉树路径节点关键值和等于目标值(LeetCode--112&LeetCode--113)
- LeetCode算法题-11.|LeetCode算法题-11. 盛最多水的容器(Swift)
- LeetCode(03)Longest|LeetCode(03)Longest Substring Without Repeating Characters
- Leetcode|Leetcode No.198打家劫舍
- cannot|cannot be read or is not a valid ZIP file
- [leetcode数组系列]1两数之和
- 数据结构和算法|LeetCode 的正确使用方式