Given a positive integernum,write a function which returns True ifnumis a perfect square else False.
Note:Do notuse any built-in library function such assqrt
.
Example 1:
Input: 16 Returns: True
Example 2:
Input: 14 Returns: False
解题方法,用二分法。因为说明了是正数,所以num>=1。
原文链接:https://www.f2er.com/go/188815.html