feat: 2025-10-28打卡
This commit is contained in:
25
367.valid-perfect-square.java
Normal file
25
367.valid-perfect-square.java
Normal file
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* @lc app=leetcode id=367 lang=java
|
||||
*
|
||||
* [367] Valid Perfect Square
|
||||
*/
|
||||
|
||||
// @lc code=start
|
||||
class Solution {
|
||||
public boolean isPerfectSquare(int num) {
|
||||
long i = 0, j = num, m;
|
||||
while(i <= j) {
|
||||
m = i + (j-i)/2;
|
||||
if(m * m == num) {
|
||||
return true;
|
||||
} else if(m * m <num) {
|
||||
i = m + 1;
|
||||
} else {
|
||||
j = m - 1;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// @lc code=end
|
||||
|
||||
Reference in New Issue
Block a user