2.png
    改下牛顿迭代,因为还是平方所以问题不大

    1. class Solution {
    2. public boolean isPerfectSquare(int num) {
    3. double x = num;
    4. while (true) {
    5. double x1 = (x + num / x) / 2;
    6. if (x - x1 < 1e-6) {
    7. break;
    8. }
    9. x = x1;
    10. }
    11. int ans = (int) x;
    12. return ans * ans == num;
    13. }
    14. }

    这么说起来和69差差不多