有效的完全平方数 Posted on 2021-11-04 Edited on 2022-04-14 In LeetCode Views: Waline: Views: Symbols count in article: 394 Reading time ≈ 1 mins. 题解方法 二分查找 二分查找 若正整数 x 满足$x \times x = num$,则 x 一定满足$1 \le x \le num$ 除 1 外的num,一定满足$ x \le num / 2$ 核心代码二分查找12345678910111213141516171819public boolean isPerfectSquare(int num) { if (num == 1) { return true; } long l = 0; long r = num / 2; while (l < r) { long mid = l + r + 1 >> 1; if (mid * mid <= num) { l = mid; } else { r = mid - 1; } } return l * l == num;} 题目来源367. 有效的完全平方数 - 力扣(LeetCode) (leetcode-cn.com)